The Game of 21 aka Subtraction Game (or Nim)

Ok, I have this complete for just the 21 game, not for 3-heap variants. The computer player will always win if a. If the game is set to 'last play wins' the computer will always win if it goes first or b. If the game is set to 'last play loses' and the user goes first, or in either case if the user doesn't know the strategy.

Code's probably too big for here so Here's the gist

but here is the 'AI' part:

public int getComputerMove()
{
    int result, best;
    if (lastPlayWins)
    {
        best = tokens % 4;
        if (best==0)
        {
            if (tokens < 4) result = tokens;
            else result = rand.nextInt(3) + 1;
        }
        else
        {
            result = best;
        }
    }
    else
    {
        best = (tokens % 4) - 1;
        if (best < 0) best = 3;
        if (best == 0) best = rand.nextInt(3) + 1;
        if (tokens <= 4 && tokens < 1) best = tokens - 1;
        if (tokens==1) best = 1;
        result = best;
    }
    System.out.println(player[1].getName() + " picks " + result + " token(s).");
    return result;
}

and some sample output:

What is your name? Philboyd_Studge
What is player 2's name, or 'computer' to play against computer? computer
What type of game would you like to play?
 (last move wins. type 'W', last move loses, type 'L') l
Enter number of rounds to play: 1
========================GAME # 1======================
TOKENS LEFT: 21
Philboyd_Studge, how many tokens do you take? 2
TOKENS LEFT: 19
NIM Bot 2000 picks 2 token(s).
TOKENS LEFT: 17
Philboyd_Studge, how many tokens do you take? 3
TOKENS LEFT: 14
NIM Bot 2000 picks 1 token(s).
TOKENS LEFT: 13
Philboyd_Studge, how many tokens do you take? 1
TOKENS LEFT: 12
NIM Bot 2000 picks 3 token(s).
TOKENS LEFT: 9
Philboyd_Studge, how many tokens do you take? 2
TOKENS LEFT: 7
NIM Bot 2000 picks 2 token(s).
TOKENS LEFT: 5
Philboyd_Studge, how many tokens do you take? 1
TOKENS LEFT: 4
NIM Bot 2000 picks 3 token(s).
TOKENS LEFT: 1
Philboyd_Studge, how many tokens do you take? 1
NIM Bot 2000 IS THE WINNER!!!============================
Player 1:Philboyd_Studge                Wins:0
Player 2:NIM Bot 2000           Wins:1
Press any key to continue . . .
/r/ProgrammingPrompts Thread