21 Sticks Game

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

Summary: Its a turn based 2 player game (player and computer).

The game starts with 21 sticks and each player can pick 1 to 4 sticks during their turn. The goal of the game is to make your opponent pick the last pick. Program: #include <stdio.h> int lineCount; void main() { int userPick; int aiPick; lineCount = 21; while (lineCount > 1) { printf("\n\n%d lines remaining. Pick 1 or 2 or 3 or 4: ", lineCount); scanf("%d", &userPick); lineCount -= userPick; if (lineCount >= 17 && lineCount <= 20) { aiPick = lineCount - 16; } else if (lineCount >= 12 && lineCount <= 15) { aiPick = lineCount - 11; } else if (lineCount >= 7 && lineCount <= 10) { aiPick = lineCount - 6; } else { aiPick = lineCount - 1; } printf("you took %d lines", userPick); printf("\nAI took %d lines", aiPick); lineCount -= aiPick; } printf("\n1 line remains and u lose\n\n"); } For detailed post visit http://www.gethugames .in/blog/2012/03/c-program-for-21-sticksgame.html For more programs visit http://www.gethugames.in/blog

You might also like