PDA

View Full Version : [GAME] Dots and Boxes



techietim
12-14-2008, 03:17 AM
1) CODE TITLE:

Dots and Boxes

2) AUTHOR NAME/NOTES:

techietim (http://www.techietim.ca)

3) DESCRIPTION:

The 2-player game of Dots and Boxes (http://en.wikipedia.org/wiki/Dots_and_boxes).

4) URL TO CODE:
http://toolbox.techietim.ca/dots_and_boxes/

Snookerman
12-14-2008, 08:41 AM
Nice! Works great in FF3 and IE7.

djr33
12-14-2008, 10:30 PM
Very cool.

A couple UI suggestions:
1. Instead of just stopping the game when a player has a majority of spaces filled, first actually fill in the rest of the space as blue/red, THEN stop it and say "blue wins", kinda like in chess when you knock the opponent's king over.

2. To make it a bit easier to click, allow clicking in the middle of a square, when that square is going to be colored blue/red. Click on 3 lines, then for the fourth you can either click on the last line or you can click in the center of the square.

3. Finally, to save even more clicking, it would be cool if, when you closed off a region, the entire region should fill in with the color-- so you don't have to work your way out. Generally, it is understood that if you seal off a region of many blocks and could potentially continue to fill them all it, that you then get them all, with just sealing off the outermost one.

Aside from that, great version of the game!

Snookerman
12-14-2008, 10:58 PM
One more UI suggestion:
I think it would be nice if the lines would have be highlighted when being hovered. After playing for a few minutes, I noticed that when trying to click the lines I would quite often miss them. Of course you could also make them thicker or make a larger clickable area, but that might be to much, I think highlighting would help a lot.

techietim
12-15-2008, 01:52 AM
@Snookerman:
Added :hover on the lines.

@djr:
Since the player can't win if the other player has over >= 51 of the squares, I makes sense to stop the game. The games are usually long enough as is.

Thanks for the suggestions!

djr33
12-15-2008, 03:01 AM
Stopping the game is fine, but it would be a really good visual clue if when it stopped the remaining squares all turned blue or red automatically also.

Nile
12-15-2008, 04:34 AM
Make the hover a darker grey.

jlizarraga
12-15-2008, 06:34 AM
Best game ever.

http://img389.imageshack.us/img389/6797/lolfu8.png

Don't judge me!

Twey
12-15-2008, 07:15 AM
Hahahaha :D
Stopping the game is fine, but it would be a really good visual clue if when it stopped the remaining squares all turned blue or red automatically also.Maybe, but the board would then not match the scores.

There are quite a few issues with this code, most of which are described in my list of common coding mistakes (http://dynamicdrive.com/forums/showpost.php?p=158839&postcount=1337).

jscheuer1
12-15-2008, 07:21 AM
Just from the perspective of playing the game, I found it boring. Perhaps if you could get the computer to play one of the colors . . .

Anyways, reminds me of battleship, which can be fun as long as you don't have to play both 'hands'.

Twey
12-15-2008, 08:15 AM
Well, it is meant to be a two-player game.

jscheuer1
12-15-2008, 08:27 AM
I'll let you click my mouse if you . . .

Seriously though, I think that would be more practical with pencil and paper.

Or - it could be played over a live connection. In fact, I'm fairly sure there is a way to do that already, but not with javascript.

I wonder though, how hard would it be to create the routines to make the browser compete with the user? if {} else if {} else {}. I mean - either there is a way to complete a box, or a way to not let the opponent complete one, or not a way to not let the opponent complete one. Just three basic states whenever the browser gets control. That is, unless I missed something about this game. Do you get a free turn if you complete a box?

Snookerman
12-15-2008, 08:34 AM
Make the hover a darker grey.
I'll second that.

Best game ever.

http://img389.imageshack.us/img389/6797/lolfu8.png

Don't judge me!
Hhahaha:D just as good as paint huh?

Just from the perspective of playing the game, I found it boring. Perhaps if you could get the computer to play one of the colors . . .

Anyways, reminds me of battleship, which can be fun as long as you don't have to play both 'hands'.
I don't think it's boring since it is a two player game, but it would be nice to have the option to play against a CPU. I assume that would require a lot more coding so, maybe a future project?

Snookerman
12-15-2008, 08:37 AM
Do you get a free turn if you complete a box?

Yup..

jscheuer1
12-15-2008, 08:50 AM
Do you get a free turn if you complete a box?

Yup..

That would definitely make the logic on the browser's side more complex.

Twey
12-15-2008, 09:11 AM
either there is a way to complete a box, or a way to not let the opponent complete one, or not a way to not let the opponent complete one.That's kind of like saying that it's easy to make a chess bot — either you can take a piece, you can stop your opponent taking a piece, or you can't stop your opponent taking a piece :) Such a bot would be easily beaten by repeated application of, say, the double-cross.

djr33
12-15-2008, 09:17 AM
The game is a lot more complex than you might think it is from first look, John.

The strategy is to draw a line while not completing the third side to any given square, in order that the opponent cannot then complete said square. More than that, it becomes a battle of wits to get the opponent to complete that third side somewhere and also to make it most valuable when it does occur. Best played, the game will result in a series of traps where a single move will open an entire path of now available boxes to be closed, and this is what makes the game complex. Coding an opponent would be cool, but it would take a lot of work to make it a strong player.

Making some sort of live one-on-one game system would be fun, but that's sorta beyond this discussion-- something I've pondered a little for a while now, with any sort of simple game. It wouldn't be particularly hard, except storing each game. It would end up having the same basic components as a chat script.

jscheuer1
12-15-2008, 09:34 AM
That would definitely make the logic on the browser's side more complex.


That's kind of like saying that it's easy to make a chess bot — either you can take a piece, you can stop your opponent taking a piece, or you can't stop your opponent taking a piece :) Such a bot would be easily beaten by repeated application of, say, the double-cross.


The game is a lot more complex than you might think it is from first look, John.

Yes, I got that. And I thought I adequately expressed having gotten that with my (above quoted) post. Apparently not. But once I knew that you get a free turn for completing a box, I saw the complexity involved. It's one thing to get a box, quite another to be forced to move again if you do.

djr33
12-15-2008, 09:54 AM
That's just a loop, really. I don't think it's any more difficult to program the computer to play the game than it was to set up the play in the first place (after all, the same rules would apply, no?). But to make it play well, that is where things get tricky.

Nile
12-15-2008, 12:54 PM
Ok, I have an idea but it's very insane. You can hook that up from ajax to a database to another computer with ajax and you can have a little waiting room.
In waiting room:
Sookerman [Challenge? Sookerman has beat 1 out of 3 games hes played]
djr3 [Challenge? djr3 has beat 3 out of 5 games hes played]
Nile [You have beat 1 out of 5 games you've played]

And then its from there, but thats a little harder.

Snookerman
12-15-2008, 01:26 PM
@John
Here is a CPU version I just googled, with different difficulty levels, it in Java so I don't know how it's done, but it can be done:
http://www.well.com/user/argv/java/dots.html (http://www.well.com/user/argv/java/dots.html)
And here's one with a less intelligent CPU, done with radio boxes:
http://www.springfrog.com/games/dots/ (http://www.springfrog.com/games/dots/)
Here is another one, this one has the feature I talked about, that the clickable area is a bit larger than the lines themselves:
http://search.teach-nology.com/web_tools/games/dots/index.html (http://search.teach-nology.com/web_tools/games/dots/index.html)
Here's another, "computer makes no mistakes" (might not be to hard to make some rules then):
http://www.grab.com/games/play-dots-and-boxes?campid=0&ssns=28& (http://www.grab.com/games/play-dots-and-boxes?campid=0&ssns=28&)
@Nile
Do you mean like an online multiplayer? That would be nice and should be easier to achieve than the CPU.
@techietim
Another suggestion, how about being able to choose the size of the board? Would that be hard to fix?

Feen
04-15-2009, 01:38 AM
3. Finally, to save even more clicking, it would be cool if, when you closed off a region, the entire region should fill in with the color-- so you don't have to work your way out. Generally, it is understood that if you seal off a region of many blocks and could potentially continue to fill them all it, that you then get them all, with just sealing off the outermost one.


Sometimes, it is convenient to not take all boxes in a chain. So, this implementation will incur nonoptimal play.