Pick 23 toothpicks

The game of "23" is a two-player game that begins with a pile of 23 toothpicks. Players take turns, withdrawing 1, 2, or 3 toothpicks at a time. The player to withdraw the last toothpick loses the game. Write a human vs computer program that plays "23". The human should always move first. When it is the computer's turn, it should play according to the following rules:

-If there are more than 4 toothpicks left, then the computer should withdraw 4 - X toothpicks, where X is the number of toothpicks the human withdrew on the previous turn.

-If there are 2 to 4 toothpicks left, then the computer should withdraw enough toothpicks to leave 1.

-If there is 1 toothpick left, then the computer has to take it and loses.

When the human player enters the number of toothpicks to withdraw, the program should perform input validation. Make sure that the entered number is between 1 and 3 and that the player is not trying to withdraw more toothpicks than exist in the pile.
@nicksho

Okay, you have the premise of the game. Do you have any code you are needing help with, to get it run smoothly?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//Write a human vs computer program that plays "23"


#include <iostream>
using namespace std;

int main()

{

int x, y;

cout << "This is a game of 23\n";
cout << "How many toothpicks will you take?(1-3)\n";
cin >> x;

  if (1<=x<=3)
   {
    y=4-x;
   }
    else if (2<23-x<4)
   {
     y=22-x;
   }
    else if (23-x==1)
   {
     y=1;
   }
  while (y<=23)

}


obviously unfinished, i just dont know what to do for the while loop
Topic archived. No new replies allowed.