Skip to content

Instantly share code, notes, and snippets.

@ZeroPivot
Created July 24, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZeroPivot/0d104c9ea10d2fa39bb662696d33498e to your computer and use it in GitHub Desktop.
Save ZeroPivot/0d104c9ea10d2fa39bb662696d33498e to your computer and use it in GitHub Desktop.
integer checkWinner(key playingPlayer)
{
integer wonOrNot = FALSE;
llSay(4, "wait");
//Eight Possibilities
if (llList2Key(row1, 0) == playingPlayer && llList2Key(row1, 1) == playingPlayer && llList2Key(row1, 2) == playingPlayer) //Possibility 1
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row2, 0) == playingPlayer && llList2Key(row2, 1) == playingPlayer && llList2Key(row2, 2) == playingPlayer) //Possibility 2
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row3, 0) == playingPlayer && llList2Key(row3, 1) == playingPlayer && llList2Key(row3, 2) == playingPlayer) //Possibility 3
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row1, 0) == playingPlayer && llList2Key(row2, 0) == playingPlayer && llList2Key(row3, 0) == playingPlayer)
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row1, 1) == playingPlayer && llList2Key(row2, 1) == playingPlayer && llList2Key(row3, 1) == playingPlayer)
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row1, 2) == playingPlayer && llList2Key(row2, 2) == playingPlayer && llList2Key(row3, 2) == playingPlayer)
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row1, 0) == playingPlayer && llList2Key(row2, 1) == playingPlayer && llList2Key(row3, 2) == playingPlayer)
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row3, 0) == playingPlayer && llList2Key(row2, 1) == playingPlayer && llList2Key(row1, 2) == playingPlayer)
{
llSay(0, llKey2Name(playingPlayer) + " won!");
wonOrNot = TRUE;
llSay(4, "ready");
}
else
if (llList2Key(row1, 0) != NULL_KEY && llList2Key(row1, 1) != NULL_KEY && llList2Key(row1, 2) != NULL_KEY && llList2Key(row2, 0) != NULL_KEY && llList2Key(row2, 1) != NULL_KEY && llList2Key(row2, 2) != NULL_KEY && llList2Key(row3, 0) != NULL_KEY && llList2Key(row3, 1) != NULL_KEY && llList2Key(row3, 2) != NULL_KEY)
{
llSay(0, "Nobody Won... Resetting Board.");
resetGame();
llSay(0, "/reset");
llSay(4, "ready");
}
llSay(4, "ready");
return wonOrNot;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment