Learn R Programming

fourinarow (version 0.1.1)

bots: Bot players for Four in a Row

Description

Computer players that select their next move based on various amounts of internal logic.

Usage

randomBot(game)

easyBot(game)

mediumBot(game)

hardBot(game)

Value

Returns an integer between 1 and 7. Each bot only selects from the set of valid moves, so they won't select a column that is already full.

Arguments

game

A 6x7 matrix object representing the current game board.

Functions

  • randomBot(): Chooses moves randomly.

  • easyBot(): Tries to make 4 in a row, but does not consider its opponents moves.

  • mediumBot(): Selects a move based on simple internal logic. It tries to make 4 in a row and tries to block the opponent from winning, but does not consider possible downstream moves.

  • hardBot(): Selects a move by looking three moves ahead (with downstream moves selected by internal logic similar to mediumBot).

Examples

Run this code
play4inaRow(randomBot, easyBot)

play4inaRow(mediumBot, hardBot)

Run the code above in your browser using DataLab