Quick noughts and crosses game AI

By [Plornt] on Dec 31, 2009

Its not great but its a small base for a tic tac toe game with a automated player.

Commands:

!ttt
then numbers

on *:TEXT:!ttt:# {
  if (%ttt != on) {
    set %ttt on
    var %i 1
    while (%i <= 9) {
      set %ttt. $+ %i 15 $+ %i
      inc %i 
    }
    msg $chan 15 1 1I 15 2 1I 15 3
    msg $chan ------------
    msg $chan 15 4 1I 15 5 1I 15 6
    msg $chan ------------
    msg $chan 15 7 1I 15 8 1I 15 9
    msg $chan Please place your marker.
    set %ttt.go $nick
  } 
}
alias mygo {
  var %i 1
  while (%i <= 9) {
    if ($strip($(%ttt. [ $+ [ %i ] ]),burc) isnum) {
      var %ttt.open %ttt.open %i
    }
    inc %i 
  }
  tokenize 32 %ttt.open
  set %ttt. $+ $($+($chr(36),$rand(1,$0)),2) 01X
}
alias win {
  unset %ttt.*
  unset %ttt
  msg $chan $iif($strip($1,burc) == x,Wewt i won!,Aww you won... this time maby... but next time YOUR MINE mwhahahAHAHAHAAH )
}
alias check {
  if (%ttt.1 == %ttt.2 && %ttt.2 == %ttt.3) { win %ttt.1 | halt }
  elseif (%ttt.4 == %ttt.5 && %ttt.5 == %ttt.6) { win %ttt.4 | halt }
  elseif (%ttt.7 == %ttt.8 && %ttt.8 == %ttt.9) { win %ttt.7 | halt }
  elseif (%ttt.1 == %ttt.4 && %ttt.4 == %ttt.7) { win %ttt.7 | halt }
  elseif (%ttt.2 == %ttt.5 && %ttt.5 == %ttt.8) { win %ttt.5 | halt }
  elseif (%ttt.3 == %ttt.6 && %ttt.6 == %ttt.9) { win %ttt.3 | halt }
  elseif (%ttt.1 == %ttt.5 && %ttt.5 == %ttt.9) { win %ttt.5 | halt }
  elseif (%ttt.7 == %ttt.5 && %ttt.5 == %ttt.3) { win %ttt.5 | halt }
}
on $*:TEXT:/^[1-9]$/:# {
  if (%ttt == on) {
    if (%ttt.go == $nick) {
      set %ttt. [ $+ [ $1 ] ] 01O 
      check
      mygo
      msg $chan  %ttt.1 1 $+ $chr(124) %ttt.2 1 $+ $chr(124) %ttt.3
      msg $chan ------------
      msg $chan  %ttt.4 1 $+ $chr(124) %ttt.5 1 $+ $chr(124) %ttt.6
      msg $chan ------------
      msg $chan  %ttt.7 1 $+ $chr(124) %ttt.8 1 $+ $chr(124) %ttt.9 
      check
    }
  }
}

Comments

Sign in to comment.
Bad_Girl   -  Jan 02, 2010

How i play this?
I do !ttt and then?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.