OU blog

Personal Blogs

neil

more groups and solitaire

Visible to anyone in the world
Edited by Neil Anderson, Friday, 20 Jan 2012, 18:39

Since my last post I've been thinking. Some messing around found me a pattern, a rather nice one for my purposes. Some background. 

I represent, even triangular Boards, as a HashMap of Pegs, some of these Pegs aren't valid. The hashCode() is just...

return (row * 10) + col;

Boards have rows and cols int properties, it doesn't make sense to rotate a Board if these are different. [Reflexion is another matter which I'll tackle later.]

When I started to think about rotation of a Board things got a little complicated. Take a ∏/2 anti-clockwise rotation. The Peg at 02 goes to 40, 05 goes to 10 etc.. Suddenly it hit me!

Take any row

10 11 12 13 14 15 16

Reverse it

16 15 14 13 12 11 10

Transpose the digits of the reversal

61 51 41 31 21 11 1

And map...

10 11 12 13 14 15 16

61 51 41 31 21 11 01

Which is the right answer and is pretty easy to programme. [Pseudo-code, I need to prove this one, I can't see any boundaries to test against.]

((Board.getRows() - Peg.getCol()) * (Peg.getRow() * 10)) + Peg.getRow();

So now I can programme a ∏/2 anti-clockwise rotation, which means I can compose to get the other rotations. Then I can loop through the pegMaps to see if they are equal (in the sense that they can be rotated onto one-another) and I can compare Boards up-to rotation.

I've come across something like this before; with Groups, conjugate cosets, permutations and equivelence. [I really do need to do some work on my Group Theory, because I know that I'm not describing this properly. I see the pattern, but I've forgotten what it's called, and means.]

Still I was right, there's more Groups to Solitaire than we thought.

 

Permalink Add your comment
Share post
neil

group action

Visible to anyone in the world

When I originally wrote the hashCode(), equals() and compareTo() methods for the Peg Class I didn't really think about comparing Boards.

Now that I'm there I see serious problems. I can write an algorithm, but even in pencil, on A4, it looks strained. And that's just for an English Board.

The problem is that Boards should be equal if you can rotate them onto one-another [I decided that reflection was out, which might be another mistake].

The good thing is that I can change things without a, "cascade of failure". The bad thing is that, for the moment, I can't see an easy way to do it.

I'm stuck with a hard choice: easy Peg, hard Board. Or vice-versa.

Permalink Add your comment
Share post
neil

parsing xml with java

Visible to anyone in the world

Is a sodding pain. I will be able to do it, eventually, but for now I'm going to leave it. It's just too fiddly and not much fun.

I can happily save as XML and use an XSLT to get what I need for now.

Really I should be working my way through unit 1 of the topology course, but I can't be bothered with that either.

Three months off have left me unable to motivate myself to do the uncongenial.

Permalink Add your comment
Share post
neil

xml

Visible to anyone in the world

After some reading and a bit of thought I know that XML is the way to go. However there's the usual bit of Java ugliness to cope with.

Java is HUGE, you can do almost anything that you want to do [except, perhaps, print]. So it's often difficult to find the actual bits & pieces, the nubbins, that you want to use. Do I want a SAX parser, or a native one?

I've printed-off many, many, pages of crap, which I'll read tonight. Tomorrow I'll write the code. By Sunday I should have somethiong that half-works.

Then I'll write the test-suite.

I am so not-better.

Permalink Add your comment
Share post
neil

as i thought

Visible to anyone in the world

[See my previous post]

Creating the XML wasn't difficult, I knew that it wouldn't be. Parsing the thing back will be a bugger.

There's a big bit of me asking why this is should be so. It's not as if XML isn't a standard. Someone should have made this easy. But..

If I bump into a bod on the street and start talking Topology [not there yet, but will be sometime soon wink], I'm seen as a benign idiot; I start talking XML and I'm a signed-up-member-of [insert your favourite hate group here].

True, the thing was, and is, used wrongly, but we can say this about any data format, can't we? Morons used it when they shouldn't, it's still better than anything else we have. Or do you fancy openDoc?

Who knows. But it is, funny? One of the major techs that drives the web is named after XML, which it doesn't use. AJAX [Asynchronous Javascipt and XML].

Only a moron loads XML, because you have to fork IE and normal browsers' javascript... [I've tried, if you want the almost working code drop me an email.]

Jings! I've just realized that I need to care not one iota about how others are going to use my stuff. I'm off the leash for once.

So it's going to be XML. Plus.

 

Permalink 2 comments (latest comment by Neil Anderson, Thursday, 12 Jan 2012, 21:17)
Share post
neil

i could use XML...

Visible to anyone in the world
Edited by Neil Anderson, Thursday, 12 Jan 2012, 17:33

You have these thoughts.

Last night I started to write the, proper, specification for version 1.0 of the solitaire thingee [codename: suzdal (not after the town! wink]. I got as far as the input/output before hitting a problem.

I knew what I wanted to do, and describing this it wasn't too hard. But when I started thinking about the how, I began to doubt—I seemed to be designing a proprietary file format. Not good, brittle. That's when I started to think XML.

Java has plenty of libraries for writing and parsing XML, I'm comfortable with XML and XSL [the sitemap for my nonsense is an PHP generated XML file]. It would seem to make sense, would it not?

The problem is that it would be quicker to build my own format and move onto the stuff that I want to do. That's the temptation—should I spend the extra time [a quick guess-timate is about five-or-six times the time] to do things properly? Whether to build something that will last, rather than just work?

If you think that's this is a no-brainer then you don't understand the problem. To do this properly will involve me being mired in online documentation and tutorials, making hundreds of adjustments to lots of classes [because I've rather built-in my current format] and writing out sequence diagrams, and such, by the score. In short it won't be much fun.

Damn it! All this OU stuff has had its effect, I have to do it right. Time to crack-open the

DocumentBuilderFactory

Docs. and get planning...well, actually not yet. Because I have the spec. to finish first don't I?

Permalink Add your comment
Share post
neil

All my holidays are over

Visible to anyone in the world
Edited by Neil Anderson, Wednesday, 11 Jan 2012, 20:43

Today I downloaded the first TMA for the Topology course; the books haven't even been posted yet. Still, come late[-ish] February the thing [the TMA] and its associated PT3 will have to be with my tutor. It's getting serious again.

So, fin de siècle, I've been playing around with my solitaire thingee. I fear that in the near future the poor beast will become neglected. No...that's not right...what's the word that I want? Oh yes, broken, utterly broken.

I've built many a poor beast over the years, all have proved flaky, shoddy, ill-considered and, in-the-end, worthless. For once, this time, I've built something that has some legs [if only in my head]. I know this because I'm having to go out of my way to break the thing; usually this happens by default. On a simple opening.

[It also does some of the things that I meant it to do.]

I don't want to destroy it. But destroy it I shall if I hopelessly-hack-at-it during the few idle moments that I'll have between now and October. Version control is all very well—you can rewind the code. What you can never do is put yourself back into, "knowing what you [meant yourself to be] do[ing]". If you have no documentation, that is.

So I've made a decision: this weekend I'll collate all the pages (bits of paper), that I can scavenge from the scattering of the floors, into a specification, I'll re-do my to-do list, I'll write down my feature requests, I'll make a plan, I'll finish the tests, I'll make sure that the Javadoc makes sense. I'll do what I should have done.

So that, at moments of stress, when maths hurts and I seek the balm of code, I might, do something useful.

Won't, won't and won't.

Permalink 2 comments (latest comment by Neil Anderson, Wednesday, 11 Jan 2012, 21:56)
Share post
neil

today

Visible to anyone in the world
Edited by Neil Anderson, Monday, 26 Dec 2011, 21:11

I've spent today lying around in my new P-Jays, listening to the wind's incessant howl and trying to hack Java.

I knew that I'd get here, to this point. to the place where I would have to start the thing all-over-again. Yes, the bloody solitaire thingee is f***ed.

That's what you get when, despite almost three years of work on, virtually, the same beast, you repeat the same mistakes. Mistakes that you knew were mistakes when you first made them.

Although I do have CASE tools I hate the damn things and won't open them up unless you are hoverring over me with an axe. I did sketch a few sequence diagrams.

But I think that I have a new in; do the plumbing first. So, for once, I'll upload a screenshoot.

Tomorrow is going to be another P-jay/Java day.

71a6133bbc9abf735b57f587e89608ab.png

Permalink Add your comment
Share post
neil

fags

Visible to anyone in the world
Edited by Neil Anderson, Wednesday, 21 Dec 2011, 19:24

I hacked away for a couple of hours today until it became obvious that I was flailing hopelessly. So I closed NetBeans and got out a notebook and pencil.

As soon as I did this it all began to come together. This often happens when you're coding—it isn't until you stop that you get an idea of the what it is that you should be doing. Of course, I know this, but I rarely use any of my knowledge.

Since my good idea [see my last post] I've been changing the architecture of the solitaire thingee. Somewhat of a silly thing to do without an entire new spec. When I started the thingee I did have a plan; but when you change said plan? Possibly a good idea to firm-up your concept of the new one? Not something that I did.

My trouble is that I play games [online Go at the present], you're not allowed to try things out, except inside of your own head; what I forget is that I spend rather a lot of my time being physical so that I can do the mental when it comes to games. Still I like to plan in the falible software of my head, despite knowing that this is an idiot thing to do.

That's why fags are important: you have to go outside; where you have to stop doing, and you have to think.

Permalink 2 comments (latest comment by ROSIE Rushton-Stone, Thursday, 22 Dec 2011, 08:10)
Share post
neil

jings

Visible to anyone in the world

What a mess. I was having trouble with loading a new game from file; it was reading all right, it just wasn't displaying. A realization dawned that I hadn't thought this through properly. Which lead me into having an idea.

Ideas are an anathema when you're actually coding—by all means have them when you are absent from the click-face, don't entertain them when you can actually try them out for real. Especially when you're struggling with some other broken thing.

Utter mess.

What's worse is that I don't have the thing under version control—crinimal negligence for a coder, I might have branched if I had been, at least I would have had a chance to go back.

I know all this stuff, and yet again, and again, I get caught in the web of my own stupidity.

It is fixable, and the idea wasn't a bad one. But I'm cracking out Hg and doing some pencil and paper work before I get stuck in again.

 

Permalink 4 comments (latest comment by Chris FInlay, Friday, 23 Dec 2011, 21:30)
Share post
neil

burning tree

Visible to anyone in the world

I wrote a failing failing-test.

When I spotted this [because of an un-wanted behaviour] and tried to fix it a firestorm developed. So I stopped coding.

A firestorm [lots of Classes suddenly saying wrong!] is a sure sign that your architecture is gang awry. The worst time to fix this is when you first spot it. Just walk away and try not to think about it, have a drink and make chips...

The strange thing about coding is that it isn't what you do that matters, it's your ability to know when not to do that counts.

Tomorrow, or some other day, I'll come back to this an it will be simple-ish. Today I would have crafted a monster.

 

Permalink Add your comment
Share post
neil

nearly

Visible to anyone in the world

I spent a few hours today hacking the Java solitaire thingee, I'm close to a landmark. Which would be a human playable GUI the can store my games to disk.

Some of its internals are a wee bit iffy, the look/GUI is awful and I really do need to revisit the unit tests. Still I'm pleased on the whole.

Mostly what I'm pleased about, is that, for once, I did something well—I'd planned an Observer pattern, but plans and fulfillment are often strangers to one another. But when I plumbed the thing together today it worked [almost] seamlessly. What was particularly pleasing was that I could insert Objects [almost everywhere] and it still, just, worked. I'd meant this to happen, but such outcomes do not always occur in my experience.

I'm tempted to crash-on. That would be a wrong thing. In a couple of places my Objects didn't perform in the way that I'd expected them to, despite the tests that I'd written. As Phil W says, the first step is to, "write a failing test". I don't have much trouble writing failing tests, but I know what he really means—if you can write the test you can write the code; and you should write  the test before you write the code.

Anyway tomorrow I write the I/O. I think that I'm going to go for string [UTF-8] and XML. And possibly HTML. I won't be serializing any Objects any-time soon methinks.

 

Permalink 2 comments (latest comment by Neil Anderson, Sunday, 11 Dec 2011, 21:32)
Share post
neil

solitaire

Visible to anyone in the world
Edited by Neil Anderson, Wednesday, 7 Dec 2011, 21:32

We get into groups.

Well, I do.

Permalink 1 comment (latest comment by Roo N, Wednesday, 7 Dec 2011, 22:23)
Share post
neil

solitaire

Visible to anyone in the world
In my madness I've decided to air my thoughts about solitaire. This may prove to be a trial to both me and you, my gentle reader. Still done now.
Permalink Add your comment
Share post
neil

seperation of concerns

Visible to anyone in the world
Edited by Neil Anderson, Sunday, 4 Dec 2011, 19:15

Today I wanted to stay in, but my wife dragged me out to exercise, "her human right to make-up". We came home cold and penniless. So I did a bit of coding.

I had a problem, which I will explain thus: we have an implementation of a board [which is part of the Model] that we wish to have the View to advertise, and the Controller to know about. Not too difficult you'd think, we use an enum to tell the view what options are available. But then the Controller has to keep up with the changes...

Or does it? And even if it does do we want to hard-code the Controller?

[Board is an Abstract Class, neither the controller nor the Vew should care about what the thing actually is; but as a board maker how do I tell the others that there's a new one? And do they have to alter their code?]

My first-thought was that I could add some methods to an enum, didn't work. But you can wrap a Class around said enum thingees. Throw in some methods and we might be on the right track. 

What I came up with is a class that exposes an enum of what's available and copes with, the inevitable, switch. You send me a switch, I'll send you an instance of what you want if you send me a String.  

public class Boards {
    private enum AvailableBoards {
        ENGLISH,
        FRENCH
    }
    public static Board getBoard(String board) {
        AvailableBoards available = AvailableBoards.valueOf(board);
        Board brd = null;
        switch (available) {
            case ENGLISH:
                brd = new English();
                break;
            case FRENCH:
                brd = new French();
                break;
        }
        return brd;
    }
}

Not finished, indeed I have a burning tree and there are several returns that need to be crafted better.

Still I think that a Class like this [at the top of a package] is a self-documenting boundary for the package. It reminds me of the [rarely-seen] javascript .config.

Permalink 5 comments (latest comment by Neil Anderson, Tuesday, 6 Dec 2011, 19:59)
Share post
neil

dependency

Visible to anyone in the world
Edited by Neil Anderson, Friday, 2 Dec 2011, 19:10

At some point in any project you are going to begin hacking; Objects are beginning to know a wee bit too much about each other, we are playing pass-the-parcel with said-same and we keep having to re-visit them to add, "positively the last method".

In short you are starting to create an Italian staple: spaghetti. And you are probably adding a piquant sauce to your error.

It doesn't matter how carefully you planned, it doesn't matter how well it looked when you drew the diagrams, it doesn't matter about your elegant proficiency with the CASE tools. You will stuff up—you'll start balling string [lower-case] into a weevil's-nest of knots. 

At this point you need to step back and plan again.

The problem is that the we think that 'our thing' is working. This is a snare, a deceit and a trap of our arrogance. Working in what sense? That it's passing the unit tests? Or that your end-users can use it [when did we care about them?], or, worse, that you can use it. Bad code is bad code. Accept that you are going to write wrong; learn to feel when you're doing that.

We don't start out to write crappy code, but write it we shall and will, and if we don't grok the moment[s] when we start to do it we will always do so. Coders need a reset: we should know when we when need a re-think of our initial mal-assumption. For such moments will come. In their droves.

My personal test is that if I change a Class and it burns the tree in a place I didn't expect it's time for serious thought.

Actually that's not my only test, there are many [if I'm starting to chain too much I get worried; my reason for disliking JQuery , but there are loads if you look] You have to develop your your own Zen in this matter.

Yup, I'm there with my Solitaire thingee.

 

Permalink 4 comments (latest comment by Neil Anderson, Sunday, 4 Dec 2011, 20:57)
Share post
neil

i have to be a good boy

Visible to anyone in the world

So I'm trying to be a good boy...

Due to extreme penuary I'm going to have to give up on the drinking and excess for the next couple of weeks. Horrid, but has to be done alas.

So I might as well make the best of a bad job and try to be good in some other areas of life. That other area would be Java.

So tonight I created a load of empty method bodies and rather too many failing tests for my liking. [I think that I have all the classes that I need—we'll see.]

I've also done some reading about MVC and I'm attempting an attempt at it.

This is probably all going to go badly wrong. That's OK, because it doesn't really matter. As long as I have some fun.

[Anyone who has ever coded knows that fun isn't something that you have—you do get something out of it, but it isn't fun.]

Permalink 4 comments (latest comment by Neil Anderson, Friday, 18 Nov 2011, 18:33)
Share post
neil

coding again

Visible to anyone in the world
Edited by Neil Anderson, Saturday, 12 Nov 2011, 21:32

Today I've spent around six hours hacking Java: good. I'm recreating my solitaire programme...not so good [I can hear some people screaming at this point.]

I don't intend to delve into history here, those of you who have been reading this blog for some time will know of this thing of old. [And Phil & Robb, who actually managed to get a working app. together last year, must be screaming the loudest.] Still.

I had a thought; what about 3-D solitaire? It was the book on partial differentiation that gave me the idea. Indirectly.

I went to bed very early last night, much drink had been taken. Thus I awoke early. I was lying in bed trying not to think about going to work, so I tried to visualize what was going on with partial differentiation. I won't bore you with my suppositions, they will be wrong, but it did get me thinking about how two 2-D solitaire boards might interact. Hence 3-D solitaire.

When I got to work [work] I started thinking about how this could be studied [some form of lego will build the board]. Which lead me to open up one of my many solitaire programmes. I thought that I could see a way to do it better...

I'm probably wrong, but if the only thing that I manage to achieve is to get me programming again then this is still gain territory. As long as I'm coding something I'm at least alive, to a certain extent.

 

Permalink Add your comment
Share post
neil

like a...

Visible to anyone in the world

dog to it's vomit I find myself skulking back into my old neighbourhood, hanging in my old haunts—I'm coding on the hoof.

True now-a-days I think a wee bit more than I used to; I now think about how I'll eventuallydo it properly. [That might be a conceit.]

I'm going to give myself an out: because I'm so rusty, I may have needed to just code without thought for a while. But, now, @ this moment, when I know that I can code all the parts [or most of them, or I know where to find out where I can, where I know that I can create the thing, where all that's needed is work...] then it's time to step back and write some specifications.

I've written the top level spec.: what I want it to do. Now I have to write the mid-level spec.: how I'm going to implement the top-level. Then it's...

What doesn't help is that my grasshopper mind has become immersed in ciphers.

 

Permalink Add your comment
Share post
neil

editor[1]

Visible to anyone in the world

Well B & Q was visited and much paint was bought, which bodes ill for the future. Some weekend soon is going to be completely buggered up with non-congenial work.

I did make time to sit down and draw up a specification for my text editor; said spec. is beyond basic but will, more than, do me for now:

  1. Create a GUI
  2. Be able to open, edit and save files

As I said: basic.

However not so easy. I've spent the last couple of hours reading the documentation, what I'm about to attempt is going to be something of a challenge.

Part of my problem is that I re-cycled my M257 unit texts [ie put them in the bin] so I don't have any hard-copy boilerplate to refer to. [Online is OK but I still prefer hard-copy.] And of course all the stuff that I created during M257 is who-knows-where.

Another issue is that Javax.swing isn't thread safe. Apparently. I'm vaguely aware of what that means—not good. So I'm going to have to be careful if I intend to use this as a base for something more powerful.

The final issue is how to chop up the code: one monolithic block? Or something a wee-bitty more flexible that will probably fall apart?

I've decided that the Input/Output [file-diddling] stuff doeshave to be hived off, but I'll try to keep the rest of the beast inside a single class. [I'll try to use inner classes just in case.]

So tomorrow we, my good wife and I, go to Asda where, amongst other purchases, I'll buy a large bottle of ertzatz red bull and get coding when I get home. Which might mean that I'll avoid, "we could do the painting this weekend..."

Permalink 4 comments (latest comment by Neil Anderson, Thursday, 3 Nov 2011, 18:11)
Share post
neil

editor

Visible to anyone in the world

Most of today has been spent piddling around doing nothing much, however some Java has been written. And that which has been written has convinced me that, at least, some of my madness is achievable.

As ever, with computing, the trick is to break the task down into manageable chunks. So to start with I'm going to write a basic text editor. In real life this would be a stupid proposition [don't re-invent the wheel], but I'm trying to learn here, so I'll let myself off.

An hour or two got me something that I can use. At which point I stopped. Which I'm proud of myself for.

There's a temptation when you're programming to just thrash ahead when things are going well. This has to be resisted—when you see that you can do something then is the time to write the specification. So that [and a visit to B & Q] are on the menu for tomorrow.

I hate writing specifications, and B & Q, but then I hate most of the text editors that I use—they have too many time-consumming features that I never want to use. it would be nice to have a bespoke one.

[Eventually I'll move all this rubbish onto my nonsense, but for now you're going to be stuck with me posting here!]

 

Permalink 1 comment (latest comment by Susan Whelan, Wednesday, 2 Nov 2011, 00:27)
Share post
neil

the mind

Visible to anyone in the world

Has it's ways.

After a week lying in bed for most of the day, reading Harry Potter books and trying not to think about anything, I'm now beginning to think again.

[I've never read any of the Potter books before, sort of a personal block; I remember JK sitting on the school-stairs writing into her notebook, one of the books that I've just read mayhaps? She was waiting for Jess; Jess who should have been playing chess! wink]

So it's back to my JavaScript Integrated Development Environment. The sodding nuisance of the thing is that I can see that it's possible. Not for me maybe, but it is for a team of programmers, there we are talking doddle.

Actually that's a two-way lie: I can do it and I think that a team of programmers would mess the thing up. So what to do?

Realistically I can't do the whole thing myself, I can pretend that I can... or can I? I could probably decide upon an architecture and then throw it open to the wolves. Should I?

That's the trouble with Open Source: your vision will be stolen from you. Which might be right, but feels wrong for you personally; they've robbed your soul. So, this one's mine, if I have to spend thirty years doing it and if it's only, or not even, useful to me...

I'll get started with the text editor stuff shall I? [Out with the big sheets of paper.]

 

 

Permalink 2 comments (latest comment by Neil Anderson, Monday, 31 Oct 2011, 22:14)
Share post
neil

Getting in touch with my inner idiot

Visible to anyone in the world

I opened up NetBeans last night, stared at it blankly for about an hour and then closed it. I couldn't think of anything that I wanted to do. The recent projects were just an accusing glut of failure. I need a new project to mess up.

When I got up this morning I began to think about something—something stupid. As the day wore on it began to look sensible. Naw, sensible isn't the right word, still stupid, but something that I might have fun doing. So here's what I plan to create...

  1. A light weight JavaScript library [yeh, that's what the world needs, another bloody JavaScript library!]
  2. A JavaScript test suite [rather like JUnit]
  3. A Java documentation creator [rather like JavaDoc]
  4. A Java compiler for JavaScript
  5. A Java IDE for JavaScript
  6. A web site to peddle the above

Madness of course, but fun madness. It won't happen, but sometimes stupid is good for the soul.

I have four months before my next course, it's time I went back to where I started to see where I am.

Permalink 2 comments (latest comment by Joyce Rae, Friday, 14 Oct 2011, 19:38)
Share post

This blog might contain posts that are only visible to logged-in users, or where only logged-in users can comment. If you have an account on the system, please log in for full access.

Total visits to this blog: 252649