An R package to provide a simple model of the popular family game Connect 4.
...or, if you prefer...
To play a game against the random bot using the built in REPL ("q" quits):
To play a game against another human:
To let the computer play against itself in a random game:
To create your own game object to play with:
game <- c4game$new(board = matrix(, nrow = 6, ncol = 7), player = 1)
This creates a new object called
game that you can then interact with.
game object will have the following fields:
- board The current state of the game board
- gamestate Usually just set to 'next' but will report if a win is detected
- player The current player, 1 or 2
game object only has one method,
dropToken. It takes a single parameter, n, where n is the number of the column the token should be dropped into.
Would drop a token into column 3 for the current user in
At this point,
game$board will update,
game$gamestate will report either
next for "next move" or "Player x wins!", and
game$player also updates to reflect the current player number, either 1 or 2.
MIT © Mark Sellors