1 Assignment
2 The Basic Game
3 The Game, with Betting
4 The interesting part
5 Handin Instructions

Assignment 1, CSC458, Spring 2010

1 Assignment

Develop the game of chutes and ladders. Specifically:

2 The Basic Game

Develop a game engine that starts a game and makes moves for each player repeatedly until the game is over. Note that in its native form, no decisions are required from a player.

Rules of Chutes & Ladders: Players both start on location zero. A turn consists of rolling a (fair) six-sided die, moving forward that number of spaces, and following any chute or ladder that starts at the space on which he or she lands. If the player ends on square 100 or would land beyond space 100, he or she wins the game. The pattern of chutes and ladders may be seen in the image linked from the wikipedia page. Note that each ladder or chute connects exactly two spaces, and "passes over" all of the intervening ones. Ignore the "move again when rolling a six" rule that wikipedia mentions. I didn’t play that way as a kid, and it’s therefore obviously wrong.

Please note that I do not expect any kind of GUI at all. A game engine at this level should be on the order of 10-100 lines of code, and running a sample game should simply tell whether player 1 won. Let’s call it runBaseGame:

runBaseGame : unit -> bool)

3 The Game, with Betting

Now, add money. In the simplest form, the winner gets a dollar. Fine, that’s simple enough. Now, let’s add a doubling cube. The doubling cube works like this: on your turn, before rolling the die, if you think the game is going well, you can "double". This means that you’d like to double the stakes. If the game was for $1 before, now it’s a game for $2. If it was $2 before, now it’s a game for $4. Et cetera. When one player doubles, the other player has the option of accepting the double, and continuing the game, or "dropping", and forfeiting the *current* stake (that is, the stake before the double). In order to prevent a player who’s winning from doubling on every turn, there’s a notion of "ownership" of the doubling cube. If player A doubles, then player B "owns" the cube, and player B is then the only one who can initiate a double. If player B does so, and the double is accepted, then the cube goes back to player A.

At the beginning of the game, the cube starts in the middle; either player can double.

Now, players have decisions to make. In particular, they have exactly two decisions to make:

doubleOrNot : (int * int -> boolean)

takeOrNot : (int * int -> boolean)

That is: "Should I double on this turn, or not?" and "Should I accept a double proferred by my opponent, or not?" The two integers represent the state of the game: the first integer indicates the space that you are on, the other integer indicates the space that your opponent is on.

Implement a simple player, consisting of definitions for each of these functions. This would probably be a good place for objects. Let’s make a Player have these two methods.

How about this:

Player.fs:

 

module Player

 

[<AbstractClass>]

type Player =

    abstract shouldDouble : int -> int -> bool

    abstract shouldTake : int -> int -> bool

So, the game itself should now accept two players, and return an integer indicating how much money player 1 won (or lost, as the case may be).

runGame : Player -> Player -> int

4 The interesting part

Can you come up with an optimal player? Give your player your last name.

5 Handin Instructions

TBA