Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: OO vs. global variables...

by John M. Dlugosz (Monsignor)
on Sep 04, 2001 at 21:25 UTC ( #110096=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://110096]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2022-01-19 21:06 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (56 votes). Check out past polls.