Hi Guys,
Just a quick question regarding what data structure would be best to implement a board game structure. I want to create a board of size n where a player draws a line from one horizontal or vertical line of the board to another. One way of doing this would be to record the x/y co-ordinates which the line is adjacent to e.g in a n = 6 board [(2,2), (3,2)] or [(5,3),(5,4)]. Also since The horizontal/vertical lines around the board can be specified like [(0,4),(1,4) or (5,6),(5,7)] would a good idea when creating the board to set the size to n + 1 to accommodate these extra x/y co-ordinates on the board. Would using sets or vectors be possible, and how should I go about starting it too? Oh and I'm using version 2.6 of python.
I'm guessing using Lists would be better because I can keep the order of the co-ordinates in the same order I want. Although I'm still confused about how to start the **** thing!
Cheers for any help!
It will depend a little bit on the exact rules of the game. Can lines intersect each other? How easily can you detect line collisions? etc.
Thanks for the reply. Basicaly the game consists of each player (one human, other AI) drawing lines from point to point and the objective is to create boxes. If a player completes a box then they get another turn to draw another line. The first player with the most completed boxes at the end wins. Its a popular game, I use to play it during lectures years ago can't remember the name though!
You may be better off with an array of some sort.
Thanks for the reply.
Orginaly I thought about an array but how would I construct it?
I am looking to implement a user-defined size: e.g: a size of 1 would create a board of one by one empty sqaure and a size of 2 would create a board of two by two squares etc. Also how would I implement the edges around the board?
I would prefer to have a co-ordinate based board because I could quickly build a version to run without a GUI first, and have the user enter their choice of co-ordinates on their move as paramaters. Which is why I thought of using sets.
Have an array of vertices, not squares. Then a line is along the edges of the squares. A 1x1 square would use a 2x2 array, 2x2 uses 3x3, etc.
Cheers.
So for example the 2 by 2 board would consist of:
.___.___.
!___!___!
!___!___!
Where the dots are the vertices.
So the array would consist of:
>>array_level1[0.0,1.0,2.0]
>>array_level2[0.1,1.1,2.1]
>>array_level3[0.2,1.2,2.2]
As x/y co-ordinates.
I could have an if statement which (because the board can't be too big) roughly says:
If user input = 1 (number of squares along)
create 1 x 1 array:
array_level1[...]
array_level2[...]
else if user input = 2
create 2 x 2 array::
array_level1[...]
array_level2[...]
array_level3[...]
else if user input = 3
create 3 x 3 array:
array_level1[...]
array_level2[...]
array_level3[...]
array_level4[...]
...
...
...
and so on till user input 5 or 6, because if I implement minimax/alpha beta only relatively small board sizes will really work.
That looks like it should work well.
I have a problem. When I use this code:
and then type board_level1 I get:Code:if str(size_of_board) == '1': board_level1 = [0.0,1.0,2.0] board_level2 = [0.1,1.1,2.1] print "Board is " + str(str(size_of_board)) + " by " + str(size_of_board)
which is correct, but when I type:Code:>>> board_level1 [0.0, 1.0, 2.0]
which is wrong. Is there anyway round this with out putting the co-ordinates in ' ' ?Code:board_level2 [0.10000000000000001, 1.1000000000000001, 2.1000000000000001]
Ok I've made some changes but now I'm completely stuck. This is my code:
But when I run it I get this:Code:def int_size_of_board(): size_of_board = int(raw_input("How many squares across do you want the game to be?")) if size_of_board == 1 or 2 or 3 or 4 or 5 or 6: dX,dY = size_of_board board = [[(i,j) for i in range(dX + 2)] for j in range(dY + 1)] print size_of_board print dX else: print 'Size too big' return board
Does anyone know why this is?Code:line 4, in int_size_of_board dX,dY = size_of_board TypeError: 'int' object is not iterable
Cheers
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks