Quote:
Originally Posted by teej51685
This is an incredibly good app. I'd love to see even just some pseudo-code describing how you got the AI to pick lines. Is it just random at first? Does it randomly pick a line and try not to give squares? Does it "count ahead" to see how many squares it is going to give away? So many questions! Bottom line, though, I'd pay for this app if it were int he app catalog.
|
Ok.
The ai consists of 4 different functions, 3-line, 2-line, end-game, and random.
Its turn on all 3 difficulties starts with the 3-line function, it looks at every box to see if it already has 3 lines, and adds the 4th to create a box. At this point, if it doesn't find a any, the easy ai moves on to selecting a line at random. The other two move to the 2-line function.
The 2-line function looks at every line and determines if selecting it would leave the human player with the ability to create a box, as it does this it creates an "off limits" list of lines and passes it to the random function, which attempts to select a line that isn't off limits (a line that wouldn't give the human player a box.) If it can't, at this point the normal ai moves onto the random line function (basically goes and gives out a box,) and the hard ai moves on to the end-game function.
The end-game function which only the hard ai uses, looks at every line and determines how long of a "stream" of boxes the it would be giving the human player by selecting it. Then it selects the line which gives away the shortest stream of boxes.
And that is basically how the ai beats you