Documentation
¶
Overview ¶
Package mnkgame implements the main parts of an m-n-k boardgame. (such as Tic Tac Toe, or Connect Four.)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( MarkerEmpty = Marker(" ") MarkerX = Marker(blackX) MarkerWhiteStone = Marker(filledWhiteCircle) MarkerBlackStone = Marker(filledBlackCircle) )
Predefine some markers.
TODO(rsned): Add more markers to choose from.
var ( Player1 = &Player{ id: "1", displayName: "Player 1", marker: MarkerX, playerType: playerTypeHuman, } Player2 = &Player{ id: "2", displayName: "Player 2", marker: MarkerWhiteStone, playerType: playerTypeHuman, } PlayerComputer1 = &Player{ id: "1001", displayName: "Computer Player Player 1", marker: MarkerWhiteStone, playerType: playerTypeComputerRandom, } PlayerComputer2 = &Player{ id: "1002", displayName: "Computer Player Player 2", marker: MarkerBlackStone, playerType: playerTypeComputerRandom, } )
Predefine some players that can be used in games.
Functions ¶
This section is empty.
Types ¶
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
Board represents the cells and their states comprising an m-n-k game. The board has a variety of optionally set attributes to make parts of the game clearer such as custom labels.
TODO(rsned): Separate rendering of board from its state management.
func (*Board) ApplyMove ¶
ApplyMove applies the given move for the given player to the board. If there are errors preventing the move, they are returned.
func (*Board) OpenPositions ¶
OpenPositions returns the set all possible cells that have not yet been filled. If there are notation labels, those values are returned. Otherwise, a list of cell coordinates is returned.
type BoardOptions ¶
type BoardOptions struct { HasOuterBorder bool // Should there be a line around the labels outside the main board. HasInnerBorder bool // Should there be a line around the main board area. HasInnerGrid bool // Should we render the lines separating each row and column. HasLabels bool // Do we have labels to show. LabelWidth int // Width of longest label to be displayed. MarkerWidth int // Width of the widest player marker symbol. Padding int // Amount of whitespace on either side of labels and markers. }
BoardOptions packages up the various settings used when rendering the game board.
type CoordsList ¶
type CoordsList []Coords
CoordsList is a list of list of Coord.
func (*CoordsList) Add ¶
func (c *CoordsList) Add(coords Coords)
Add attempts to add the given value, skipping if the value already is in this.
This method assuemes the input is in the same order as existing values. Permutations are NOT checked and are considered distinct.
type MNKGame ¶
type MNKGame struct {
// contains filtered or unexported fields
}
An MNKGame is an abstract board game in which two players take turns in placing a stone of their color on an m-by-n board, the winner being the player who first gets k stones of their own color in a row, horizontally, vertically, or diagonally.
func TicTacToe ¶
TicTacToe returns a new instance of an m-n-k game as defined by the common Tic Tac Toe rules.
func (*MNKGame) ApplyMove ¶
ApplyMove attempts to apply the users choice of move. If any errors occur, such as an illegal move, the error will be non-nil.
func (*MNKGame) OpenPositions ¶
OpenPositions returns a list of all the open positions on the board.
func (*MNKGame) Outcome ¶
Outcome reports the current status of the game for each player.
TODO(rsned): Convert this to take a player and return their outcome to make it easier to simplify the game loop.
func (*MNKGame) PotentialMoves ¶
PotentialMoves returns a list of potential moves available.
TODO(rsned): Augment this to support games like Nine Mens Morris and others that allow markers to move after they have been played.
func (*MNKGame) RenderBoard ¶
RenderBoard returns a string representation of the current board state.
type Marker ¶
type Marker string
Marker represents the various pre-defined markers that may appear in the games.
type Outcome ¶
type Outcome int
Outcome is an enumeration of the various possible states of a game.
Define the enumeration of outcomes.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player holds basic fields about a player in this game, primarily what type of player and what marker it uses.
func (*Player) SetComputer ¶
func (p *Player) SetComputer()
SetComputer sets the player type to be a computer making random moves.