Ejemplo n.º 1
0
func (b *board) setPiece() {
	if err := rules.CheckOccupied(b.sY, b.sX, &b.tiles); err != nil {
		b.comHud <- err.Error()
		if b.turn == AI1 || b.turn == AI2 {
			b.ComOut <- b.tiles
		}
		return
	}
	if b.turn == P1 || b.turn == AI1 {
		b.tilesDisp[b.sY][b.sX].black()
		b.tiles[b.sY][b.sX] = b.player1
		b.turn = b.player2
		if b.player2 == AI2 {
			b.ComOut <- b.tiles
		}
	} else {
		b.tilesDisp[b.sY][b.sX].white()
		b.tiles[b.sY][b.sX] = b.player2
		b.turn = b.player1
		if b.player1 == AI1 {
			b.ComOut <- b.tiles
		}
	}
	if err, _ := rules.CheckWin(b.sY, b.sX, &b.tiles); err != nil {
		if b.turn == b.player1 {
			b.state = WINP2
			b.comHud <- err.Error() + " player 2"
		} else {
			b.state = WINP1
			b.comHud <- err.Error() + " player 1"
		}
	}
}
Ejemplo n.º 2
0
func Heur(node *[boardSize][boardSize]int8, player int8) (count float64) {
	for y := int8(0); y < boardSize; y++ {
		for x := int8(0); x < boardSize; x++ {
			if node[y][x] == player {
				_, score := rules.CheckWin(y, x, node)
				count += float64(score)
			}
		}
	}
	return
}
Ejemplo n.º 3
0
func (a *Arena) move(player int8) error {
	a.ais[player-1].ComIn <- a.board
	move := <-a.ais[player-1].ComOut
	if a.board[move[0]][move[1]] != 0 {
		y, x := rand.Intn(19), rand.Intn(19)
		for a.board[y][x] != 0 {
			y, x = rand.Intn(19), rand.Intn(19)
		}
		a.board[y][x] = player
		win, _ := rules.CheckWin(move[0], move[1], &a.board)
		if win != nil {
			return errors.New("draw")
		}
		return errors.New("space already occupied")
	}
	a.board[move[0]][move[1]] = player
	win, _ := rules.CheckWin(move[0], move[1], &a.board)
	if win != nil {
		return win
	}
	return nil
}