Documentation
¶
Index ¶
- func CountPieces(board Board) (int, int)
- func CountPiecesBitBoard(bb BitBoard) (int, int)
- func HasAnyMoves(board Board, playerColor Piece) bool
- func IsGameFinished(board Board) bool
- func IsGameFinishedBitBoard(bb BitBoard) bool
- func IsValidMove(board Board, playerColor Piece, pos Position) bool
- type BitBoard
- type Board
- type Game
- func (g *Game) ApplyMove(pos Position) bool
- func (g *Game) CountPiecesMethod() (int, int)
- func (g *Game) DisplayBoard(board Board)
- func (g *Game) GetNewBoardAfterMoveMethod(pos Position) (Board, bool)
- func (g *Game) GetOtherPlayerMethod() Player
- func (g *Game) GetValidMovesForCurrentPlayer() []Position
- func (g *Game) GetWinnerMethod() Piece
- func (g *Game) HasAnyMovesInGame() bool
- func (g *Game) IsGameFinishedMethod() bool
- type Piece
- type Player
- type Position
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountPieces ¶
CountPieces counts the number of pieces of each color on the board Returns the count of black pieces and white pieces
func CountPiecesBitBoard ¶
func HasAnyMoves ¶
HasAnyMoves checks if there are any valid moves for a given player color on a board
func IsGameFinished ¶
IsGameFinished checks if the game is over on a given board by determining if any valid moves remain The game is finished when neither player has any valid moves
func IsGameFinishedBitBoard ¶
func IsValidMove ¶
IsValidMove checks if placing a piece of the given color at the specified position is a valid move. A move is valid if it results in flipping at least one opponent's piece.
Parameters:
- board: The current game board state
- playerColor: The color of the piece to be placed (Black or White)
- pos: The position where the piece would be placed
Returns:
- bool: true if the move is valid, false otherwise
Types ¶
type BitBoard ¶
func ApplyMoveToBitBoard ¶
ApplyMoveToBitBoard applies a move to a bitboard and returns the new bitboard state
type Board ¶
type Board [8][8]Piece
func ApplyMoveToBoard ¶
ApplyMoveToBoard applies a move to a board and returns the new board state without modifying the original board. Returns a new board and whether the move was valid. ApplyMoveToBoard applies the specified move to the game board and returns the new board state.
This function performs the following steps: 1. Validates if the move is legal using IsValidMove 2. Places the player's piece at the specified position 3. Flips opponent pieces in all 8 directions according to Othello rules
Parameters:
- board: The current state of the game board
- playerColor: The color of the player making the move (BLACK or WHITE)
- pos: The position where the player wants to place their piece
Returns:
- The updated board after applying the move
- A boolean indicating whether the move was successfully applied (true) or invalid (false)
If the move is invalid, the original board is returned unchanged with false as the second return value.
type Game ¶
type Game struct {
Board Board
Players [2]Player
CurrentPlayer Player
NbMoves int
History []Position
}
Game represents the state of an Othello game. It contains the game board, the two players, the current player's turn, and the number of moves that have been made in the game. This struct is used to maintain the complete state of a game session.
func NewGame ¶
NewGame creates and initializes a new Othello game. It sets up the board with the standard initial position where four pieces are placed in the center of the board (two black and two white in a diagonal pattern). The function also initializes both players, sets Black as the first player to move, and initializes the move counter to zero. Returns a ready-to-play Game instance.
func (*Game) CountPiecesMethod ¶
CountPiecesMethod is a method wrapper for CountPieces
func (*Game) DisplayBoard ¶
DisplayBoard prints a representation of the board to the console DisplayBoard prints the current state of the Othello board to the console. The function displays column letters (A-H) across the top and row numbers (1-8) along the left side, using chess-style notation. Empty cells are shown as "·", black pieces as "●", and white pieces as "○".
Parameters:
- board: The Board to display
func (*Game) GetNewBoardAfterMoveMethod ¶
GetNewBoardAfterMoveMethod is a method wrapper for GetNewBoardAfterMove
func (*Game) GetOtherPlayerMethod ¶
GetOtherPlayerMethod is a method wrapper for GetOtherPlayer
func (*Game) GetValidMovesForCurrentPlayer ¶
GetValidMovesForCurrentPlayer is a method wrapper for the ValidMoves function
func (*Game) GetWinnerMethod ¶
GetWinnerMethod is a method wrapper for GetWinner
func (*Game) HasAnyMovesInGame ¶
HasAnyMovesInGame is a method wrapper for HasAnyMoves
func (*Game) IsGameFinishedMethod ¶
IsGameFinishedMethod is a method wrapper for IsGameFinished
type Piece ¶
type Piece int
func GetOpponentColor ¶
GetOpponentColor returns the opposite color of the given player color
func GetWinner ¶
GetWinner returns the winner of the game (color with more pieces) If it's a tie, returns Empty GetWinner determines the winner of an Othello game based on the current board. It counts the number of black and white pieces on the board and returns: - Black if there are more black pieces - White if there are more white pieces - Empty if there's a tie (equal number of black and white pieces)
Parameters:
- board: The game board to evaluate
Returns:
- Piece: The winning piece color (Black, White) or Empty in case of a tie
type Player ¶
func GetOtherPlayer ¶
GetOtherPlayer returns the Player object with the opposite color GetOtherPlayer returns the opponent player given the current player's color. It takes an array of two players and the current player's color as arguments, then returns the player whose color differs from the current player's color. This function is useful for alternating turns in the game.
type Position ¶
func ValidMoves ¶
ValidMoves returns all valid moves for a player on a given board
func ValidMovesBitBoard ¶
ValidMovesBitBoard returns all valid moves for a player using state-of-the-art bitboard operations Uses optimized Kogge-Stone sliding attack generation for maximum performance