//----------------------------------Tic Tac Toe------------------ Select.tttgame{ OnPlayOX } //OX游戏,by Pygmalion, loosely translated by Zar //edited some by vita to have the AI make mistakes //------------------------------------------- OnPlayOX { //intializing a tictactoe array with all 0's arrOX = IARRAY for _i = 0; _i < 9; _i++ { arrOX = (arrOX, 0) } "\0\s[0]Tic-tac-toe?\w4 Okie!\w9\w9\c" "\0\s[0]Xs and Os, huh?\w4 Let's start!\w9\w9\c" "\0\s[5]Tic-tac-toe, huh.\w4 Think you can beat me?\w9\w9\c" "\0\s[1]Tic-tac-toe, start!\w9\w9\c" -- PlayOXshow(0) } PlayOXshow { //this function prints out the tictactoe array _tempstr = "" for _i = 0; _i < 3; _i++ { for _j = 0; _j < 3; _j++ { _temp = _i * 3 + _j if arrOX[_temp] == -1 _tempstr = _tempstr + "X" elseif arrOX[_temp] == 1 _tempstr = _tempstr + "O" elseif _argv[0] == 0 _tempstr = _tempstr + "\q[ ,PlayOXrun("+_temp+")]" else _tempstr = _tempstr + " " if _j != 2 _tempstr = _tempstr + " | " } _tempstr = _tempstr + "\n[90]" if _i != 2 { _tempstr = _tempstr + "------------" } _tempstr = _tempstr + "\n[90]" } //switching btwn what dialogue to give. -> is the game over or not? switch _argv[0] { "\_q\0\s[0]\b[2]%(username)'s turn!\n\n%(_tempstr)\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" { "\_q\0\s[0]\b[2]\n%(_tempstr)\n[half]\_q\s[3]I lost...\w8 \s[5]Lemme try again!\w9\w9\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" "\_q\0\s[0]\b[2]\n%(_tempstr)\n[half]\_qOh, you beat me, %(username)?\w4\s[5] Good job!\w8\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" "\_q\0\s[0]\b[2]\n%(_tempstr)\n[half]\_qAh, so you won...\w4\s[7] I'm not gonna give up!!\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" } { "\_q\0\s[9]\b[2]\n%(_tempstr)\n[half]\_q\Guess it's a tie, huh.\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" "\_q\0\s[9]\b[2]\n%(_tempstr)\n[half]\_qWelp, it's a tie.\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" "\_q\0\s[3]\b[2]\n%(_tempstr)\n[half]\_qWe tied...\w4 Wanna try again?\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" } { "\_q\0\s[6]\b[2]\n%(_tempstr)\n[half]\_q\nI won!\w4 Woohoo!\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" "\_q\0\s[1]\b[2]\n%(_tempstr)\n[half]\_q\nI win, %(username).\w4 Better luck next time.\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" "\_q\0\s[5]\b[2]\n%(_tempstr)\n[half]\_q\nAlright!\w I'm a tic-tac-toe champion!\n[150]\_q\![*]\q[Play Again,OnPlayOX]\n\n[half]Back to...\n\n[half]\![*]\q[Games menu,OnGamesMenu]\n\![*]\q[Main menu,OnBACKTOMENU]\e" } } } Select.PlayOXrun { arrOX[_argv[0]] = -1 if PlayOXover(_argv[0]) != 1 { _tempid = -1 _rightmax = -24 _tempright = 0 //loop through ox array for _i = 0; _i < 9; _i++ { //if it's a blank spot if arrOX[_i] == 0 { //check if this would make a win for the AI arrOX[_i] = 1 if PlayOXover(_i) == 1 { arrOX[_i] = 0 _tempid = _i break } _rightmin = 24 for _j = 0; _j < 9; _j++ { if arrOX[_j] == 0 { //anticipate the player's next move arrOX[_j] = -1 _tempright = 0 _temparry = IARRAY _temparry = (_temparry,arrOX[0] + arrOX[1] + arrOX[2]) //row 1 _temparry = (_temparry,arrOX[3] + arrOX[4] + arrOX[5]) //row 2 _temparry = (_temparry,arrOX[6] + arrOX[7] + arrOX[8]) //row 3 _temparry = (_temparry,arrOX[0] + arrOX[3] + arrOX[6]) //col 1 _temparry = (_temparry,arrOX[1] + arrOX[4] + arrOX[7]) //col 2 _temparry = (_temparry,arrOX[2] + arrOX[5] + arrOX[8]) //col 3 _temparry = (_temparry,arrOX[0] + arrOX[4] + arrOX[8]) //diag 1 _temparry = (_temparry,arrOX[2] + arrOX[4] + arrOX[6]) //diag 2 _oxnum = 0 foreach _temparry; _k { _tempright += _k if _k == -3 _oxnum = 24 if _k == -2 _oxnum++ if _k == 2 _oxnum-- } if _oxnum > 1 _tempright = -24 if _tempright < _rightmin { _rightmin = _tempright } arrOX[_j] = 0 } } if _rightmin > _rightmax { _rightmax = _rightmin _tempid = _i } //change back arrOX[_i] = 0 } } //determine if there are spaces left if (_tempid == -1) { //if so, semi-randomly pick a spot _tempid = OXMistakes() } //if tempid unchanged, its a tie if _tempid == -1 { PlayOXshow(2) } else { //make a move -> winning move for AI if found early on //tweak the chance as you feel like if RAND(100) < 15 { //function to determine random mistakes _tempid = OXMistakes() arrOX[_tempid] = 1 } else { arrOX[_tempid] = 1 } //if the move the AI made results in a win for the AI, show the win sentence for the AI, else continue if PlayOXover(_tempid) == 1 { PlayOXshow(3) } else { PlayOXshow(0) } } } else //if the move the player made results in a win display player win dialogue PlayOXshow(1) } PlayOXover { //function to determine if the tictactoe game is over (and one of the players have won) //argv is the square to check _nowrow = _argv[0] / 3 _nowcolumn = _argv[0] % 3 //first two check row and column for a completed line of x's or o's //last two check diagonals if arrOX[_nowrow*3] == arrOX[_nowrow*3+1] && arrOX[_nowrow*3+1] == arrOX[_nowrow*3+2] && arrOX[_nowrow*3] != 0 / || arrOX[_nowcolumn] == arrOX[3+_nowcolumn] && arrOX[3+_nowcolumn] == arrOX[6+_nowcolumn] && arrOX[_nowcolumn] != 0 / || arrOX[0] == arrOX[4] && arrOX[4] == arrOX[8] && arrOX[8] != 0 / || arrOX[2] == arrOX[4] && arrOX[4] == arrOX[6] && arrOX[6] != 0 { 1 } else 0 } //first pass at adding in mistakes OXMistakes { //randomly pick a spot, else pick the first open spot if the random spot picked is already filled _OXspot = RAND(9) if arrOX[_OXspot] == 0 { _OXspot } else { for _i = 0; _i < 9; _i++ { if arrOX[_i] == 0 { _i } } -1 } }