http://qs321.pair.com?node_id=110096


in reply to OO vs. global variables...

Will you have more than one board?

I think yes, because in the implementation I'm familiar with, the board state is thought-ahead as it forms the minmax tree. Each point in the thinking-ahead points to its own "what if" board. So yes, everything in the code needs to be told which board to use. Board means "current entire state of the game".

Can you use constant board_size=>8; ? Sure, that's not a problem and the global police won't get after you. But it won't really be global, it will be in the package used for the board object. It's a class invariant, not a "global", right?

Possible solution:

Standard implementation of minmax tree. Generate a tree for every possible move, several moves deep. On odd levels you want the MIN result (bad for the player), on even levels (computer's play) you want the MAX result. If you can see all the way to the end of the game you know the result is infinite if it results in a win for that player. But you generally can't, so you make things much more complex by guessing if the board looks like its in a favorible state. Sort each row as you go, because you quit digging when you beat what you already have.

The book I learned this from is this one. —John