My idea of that is to use number representing each block. For example, a 3 x 3 block may looks like this:
and the program may interpret each block as a number:
so when the player want to choose a block to occupy, he or she actually choose a number from 1 to 9 to represent the block.
Then mechanism of deciding winner goes a little bit more complicate. There are generally four patterns of winning situation:
OOX n, n+1
XOO n+size+1, n+size+2
XXX
OXX n
OOX n+size, n+size+1
XOX n+2*size+1
XOX n
OOX n+size-1, n+size
OXX n+2size-1
XOO n, n+1
OOX n+size-1, n+size
XXX
* size is a variable means the length of each row.
Imagine this, player 1 choose a move for four times, all his or her moves are recorded in a list, we sort the list and see if the four numbers match the pattern of the four numbers I listed above. However, we need to avoid the situation which like this:
XOO
XXO
OXX
It also follows the pattern (first block = n, second block = n+1, third block = n+size+1, fourth block = n+size+2), and from this we see that the first block cannot not be larger than n*size-2, in other words:
a//size or (a+1)//size would return a False.
These things are just conceptual level, but I think it is practical and is able to change to code.


没有评论:
发表评论