Esempio n. 1
0
//PlacePiece attempts to place a piece at vector
func (b *Board) PlacePiece(vector Vector, ownerID int) error {
	if vector.X >= b.Dimensions.X || vector.Y >= b.Dimensions.Y {
		return errors.NewOutOfBounds("Board")
	}
	space := &b.Spaces[vector.X][vector.Y]
	space.HasPiece = true
	space.Piece = Piece{10, ownerID}
	return nil
}
Esempio n. 2
0
//ApplyMove moves the piece according to move given
func (b *Board) ApplyMove(move Move) error {
	if !move.PieceCoords.InBoundsOf(b.Dimensions) {
		return errors.NewOutOfBounds("Board")
	}
	space := &b.Spaces[move.PieceCoords.X][move.PieceCoords.Y]
	if !space.HasPiece {
		return errors.New("No piece at space provided")
	}
	piece := space.Piece
	newLocation := move.PieceCoords.Add(move.Vector)
	if !newLocation.InBoundsOf(b.Dimensions) {
		return errors.NewOutOfBounds("Board")
	}
	newSpace := &b.Spaces[newLocation.X][newLocation.Y]
	newSpace.Piece = piece
	newSpace.HasPiece = true
	space.Piece = Piece{}
	space.HasPiece = false
	return nil
}