コード例 #1
0
ファイル: player.go プロジェクト: svera/acquire
// HasTile checks if the passed tile is in player's hand
func (p *Player) HasTile(tile interfaces.Tile) bool {
	for _, currentTile := range p.tiles {
		if currentTile.Number() == tile.Number() && currentTile.Letter() == tile.Letter() {
			return true
		}
	}
	return false
}
コード例 #2
0
ファイル: tileset.go プロジェクト: svera/acquire
// DiscardTile removes passed tile from the tileset
func (t *Tileset) DiscardTile(tl interfaces.Tile) {
	for i, currentTile := range t.tiles {
		if currentTile.Number() == tl.Number() && currentTile.Letter() == tl.Letter() {
			t.tiles = append(t.tiles[:i], t.tiles[i+1:]...)
			break
		}
	}
}
コード例 #3
0
ファイル: board.go プロジェクト: svera/acquire
// TileMergeCorporations checks if the passed tile merges two or more corporations, returns a map of
// corporations categorized between "acquirer" and "defunct"
func (b *Board) TileMergeCorporations(t interfaces.Tile) (bool, map[string][]interfaces.Corporation) {
	corporations := b.AdjacentCorporations(t.Number(), t.Letter())

	if len(corporations) > 1 {
		return true, categorizeMerge(corporations)
	}
	return false, map[string][]interfaces.Corporation{}
}
コード例 #4
0
ファイル: player.go プロジェクト: svera/acquire
// DiscardTile discards the passed tile from player's hand
func (p *Player) DiscardTile(tile interfaces.Tile) interfaces.Player {
	for i, currentTile := range p.tiles {
		if currentTile.Number() == tile.Number() && currentTile.Letter() == tile.Letter() {
			p.tiles = append(p.tiles[:i], p.tiles[i+1:]...)
			return p
		}
	}
	return p
}
コード例 #5
0
ファイル: game.go プロジェクト: svera/acquire
// Returns true if a tile is permanently unplayable, that is,
// that putting it on the board would merge two or more safe corporations
func (g *Game) isTilePermanentlyUnplayable(tl interfaces.Tile) bool {
	adjacents := g.board.AdjacentCorporations(tl.Number(), tl.Letter())
	safeNeighbours := 0
	for _, adjacent := range adjacents {
		if adjacent.IsSafe() {
			safeNeighbours++
		}
		if safeNeighbours == 2 {
			return true
		}
	}
	return false
}
コード例 #6
0
ファイル: board.go プロジェクト: svera/acquire
// TileFoundCorporation checks if the passed tile founds a new corporation, returns a slice of tiles
// composing this corporation
func (b *Board) TileFoundCorporation(t interfaces.Tile) (bool, []interfaces.Tile) {
	var newCorporationTiles []interfaces.Tile
	adjacent := b.adjacentTiles(t.Number(), t.Letter())
	for _, adjacentTile := range adjacent {
		if adjacentTile.Type() == interfaces.CorporationOwner {
			return false, []interfaces.Tile{}
		}
		newCorporationTiles = append(newCorporationTiles, adjacentTile.(interfaces.Tile))
	}
	if len(newCorporationTiles) > 0 {
		newCorporationTiles = append(newCorporationTiles, t)
		return true, newCorporationTiles
	}
	return false, newCorporationTiles
}
コード例 #7
0
ファイル: board.go プロジェクト: svera/acquire
// TileGrowCorporation checks if the passed tile grows a corporation.
// Returns true if that's the case, the tiles to append to the corporation and
// the ID of the corporation which grows
func (b *Board) TileGrowCorporation(tl interfaces.Tile) (bool, []interfaces.Tile, interfaces.Corporation) {
	tilesToAppend := []interfaces.Tile{tl}
	var corporationToGrow, nullCorporation interfaces.Corporation

	corporations := b.AdjacentCorporations(tl.Number(), tl.Letter())
	if len(corporations) != 1 {
		return false, []interfaces.Tile{}, nullCorporation
	}
	corporationToGrow = corporations[0]

	adjacent := b.adjacentTiles(tl.Number(), tl.Letter())
	for _, adjacentCell := range adjacent {
		if adjacentCell.Type() == interfaces.UnincorporatedOwner {
			tilesToAppend = append(tilesToAppend, adjacentCell.(interfaces.Tile))
		}
	}
	return true, tilesToAppend, corporationToGrow
}
コード例 #8
0
ファイル: game.go プロジェクト: svera/acquire
// Returns true if a tile is temporarily unplayable, that is,
// that putting it on the board would create an 8th corporation
func (g *Game) isTileTemporarilyUnplayable(tl interfaces.Tile) bool {
	if len(g.activeCorporations()) < totalCorporations {
		return false
	}
	adjacents := g.board.AdjacentCells(tl.Number(), tl.Letter())
	emptyAdjacentCells := 0
	for _, adjacent := range adjacents {
		if adjacent.Type() == interfaces.CorporationOwner {
			return false
		}
		if adjacent.Type() == interfaces.EmptyOwner {
			emptyAdjacentCells++
		}
	}
	if emptyAdjacentCells == len(adjacents) {
		return false
	}
	return true
}
コード例 #9
0
ファイル: board.go プロジェクト: svera/acquire
// PutTile puts the passed tile on the board
func (b *Board) PutTile(t interfaces.Tile) interfaces.Board {
	b.grid[t.Number()][t.Letter()] = t
	return b
}