ina soepangkat wrote

> 
> hi, list..
> do any of you guys had experience of making a game like tic tac toe in
> lingo?
> I am having problem checking the winner in the diagonal form. Anybody can
> help me put of this misery? :) I really appreciate it if you do...
> 
> thanks,
> ina

Hi,

This isn't really a direct answer to your question - but when I made a
little tic-tac-toe game, I just had a list of winning states and searched
through this. For example,


on mInit me
  wins = []
  wins.append([1,2,3])
  wins.append([4,5,6])
  wins.append([7,8,9])
  wins.append([1,4,7])
  wins.append([2,5,8])
  wins.append([3,6,9])
  wins.append([1,5,9])
  wins.append([3,5,7])
end

on mCheckForWin me, pState, playerID
    -- the game state was a list like this
    -- [0,0,"X","O","X",0,0,0, 0]
    -- the playerID was either "X" or "O"
  repeat with j = 1 to 8 -- 8 possible wins
    thisWin = wins[j]
    hits = []
    repeat with i = 1 to 3
      if pState[thisWin[i]] = playerID then hits.append(thisWin[i])
      else exit repeat
    end repeat
    if hits.count = 3 then return hits
  end repeat
end

You could prune the search (eg. if the player doesn't have grid location 1,
then that rules out wins 1, 4 and 7 -- but since it is such as small state
space, I figured that director would repeat through a bunch of lists quicker
than trying to do some fancy maths).

Luke 


-- PS. Are you creating a programmed AI opponent for the game?

Luke


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to