The Game of NIM

this lab is really not that hard. Much easier than the last one. It should just be a little tricky, and fun. Reinforcing your new programming skills.

This is a well known game with little tricks.

The game is played with two players alternately take marbles from a pile. In each move, a player chooses how many marbles to take. The player must take at least one but at most half of the marbles. Then the other players takes a turn. The player who takes the last marble loses.

Write a program in which the computer plays against a human opponent.

Generate a random integer between 10 and 100 to represent the original stack of marbles.

Generate another random number between 0 and 1 to determine who goes first, computer or player.

Generate another random number between 0 and 1 to determine if the computer plays smart or stupid.

In stupid mode the computer simply takes a random number of marbles between 1 and n/2 (n being the total marbles).

In smart mode the computer takes off enough marbles to make the size of the pile a power of two minus 1 -- that is 3, 7, 15, 31 or 63. (example 2^2 - 1 = 3 and 2^3 - 1 = 7 and 2^4 - 1 = 15). This will always work unless the pile is 1 less than ppower of 2, so in that case the computer will take a random legal move.

See if you can beat the computer if it goes first, if you programmed it correctly you can't.


This will be graded on the program working, by allowing a human player to play against the computer following the rules and a winner is decided.

Proper programming skills, good clear variable definitions, good class structure, and the proper use of methods will all be graded. As well as properly commented code.

Turn in

Your program will be due 5pm December 3rd. No late assignments will be accepted. Turn in what you get done if you don't finish it. All assignments should be turned in to your lab TA.

Habilidades: Java

Ver mais: what is game programming, what is a variable in programming, what is a variable in computer programming, the nim game, the game of nim, the game nim, programming definitions, programming a computer game, play nim game, nim number, nim game rules, nim game play, nim game code, n 2 the game, n 2 game, last nim, is it programming fun, is computer programming hard, how to play nim, how hard is computer programming, game of nim, game nim, fun in december, first lab, first computer programming

Acerca do Empregador:
( 2 comentários ) BOZEMAN, United States

ID do Projeto: #5145907

1 freelancer está ofertando em média $15 para este trabalho


Hired by the Employer

$15 USD / hora
(16 Comentários)