Learn R Programming

fourinarow (version 0.1.1)

play4inaRow: Play a game of Four in a Row

Description

Play a game of Four in a Row

Usage

play4inaRow(playerOne, playerTwo, verbose = TRUE)

Value

Returns 1 or 2 to indicate whether Player 1 or Player 2 was the winner. Returns 0 in the case of a tie.

Arguments

playerOne

A function that takes the current board as input and returns the next move (1-7) for Player 1.

playerTwo

Same for Player 2. Note that both functions see their pieces as "X" and opponent's pieces as "O".

verbose

Logical value indicating whether or not to print the final board to the console (default is TRUE)

Details

The game is played on a \(6 \times 7\) grid and players alternate placing markers in one of the \(7\) columns. The piece will "fall" to the lowest unoccupied space in that column. The game ends when one player wins by getting four pieces in a row (horizontally, vertically, or diagonally).

Note that every player will see their markers as Xs when it is their turn.

Examples

Run this code
play4inaRow(randomBot, randomBot)

Run the code above in your browser using DataLab