From 265b50e1de0345c88612a0a623954c00077cc592 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 21 Feb 2023 21:58:44 -0500 Subject: make sure AI knows that only pawns can kill en passant pawns --- Main.gd | 54 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/Main.gd b/Main.gd index ea47a80..636f9f9 100644 --- a/Main.gd +++ b/Main.gd @@ -38,6 +38,10 @@ func _ready(): #checkmatet1() #checkmatet2() + #spawn_piece("pawn", "teal", 2, 6, team1) + #spawn_piece("pawn", "red", 3, 4, team2) + #spawn_piece("rook", "red", 0, 5, team2) + var captures = update_capture_tables(board_to_text_board(board)) team1_capture = captures[0] team2_capture = captures[1] @@ -107,8 +111,13 @@ func ai_move(team, text_board, ai_mode=ai_modes.purely_random): ai_random_move(legal_every_move) elif ai_mode == ai_modes.weighted_random: ai_weighted_random(team, text_board, legal_every_move) + elif ai_mode == ai_modes.minimax_depth_2: + ai_minimax_depth_2(team, text_board, legal_every_move) new_turn() +func ai_minimax_depth_2(team, text_board, legal_every_move): + pass + func ai_make_move(piece, move): var pos = position_to_board_cell(Vector2(piece[0] * board_cell, piece[1] * board_cell)) var board_piece = board[pos[0]][pos[1]] @@ -163,7 +172,11 @@ func ai_weighted_random(team, text_board, legal_every_move): var moves = every_move[1] if moves: for move in moves: - if p_board[move[0]][move[1]] > 0: + if p_board[move[0]][move[1]] is Array: + # en passant 'move' specifically does array + if piece[2] == piece_names.pawn: + saved_moves.append([p_board[move[0]][move[1]], piece, move]) + elif p_board[move[0]][move[1]] > 0: saved_moves.append([p_board[move[0]][move[1]], piece, move]) else: continue @@ -188,39 +201,50 @@ func generate_points_board(team, text_board): for k in 8: var piece = text_board[i][k] if piece: - match piece[0]: + match piece[text_board_ele.piece_enum]: piece_names.pawn: - if piece[1] == team: + if piece[text_board_ele.team] == team: # our pawn p_board[i][k] = -1 * ai_weights.pawn - else: + if piece[text_board_ele.en_passant]: + print("this teams (%s) pawn is en passant, on our team" % piece[text_board_ele.team]) + pass + else: # their pawn p_board[i][k] = ai_weights.pawn + if piece[text_board_ele.en_passant]: + print("this teams (%s) pawn is en passant, on enemy team" % piece[text_board_ele.team]) + if team == team1: # they'll be team2 here + p_board[i][(k - 1)] = [ai_weights.pawn, true] + else: # they'll be team1 here + # team1 pawn goes 'up' -1 or -2 each movement, so the space behind it will be +1 + p_board[i][(k + 1)] = [ai_weights.pawn, true] piece_names.rook: - if piece[1] == team: + if piece[text_board_ele.team] == team: p_board[i][k] = -1 * ai_weights.rook else: p_board[i][k] = ai_weights.rook piece_names.knight: - if piece[1] == team: + if piece[text_board_ele.team] == team: p_board[i][k] = -1 * ai_weights.knight else: p_board[i][k] = ai_weights.knight piece_names.bishop: - if piece[1] == team: + if piece[text_board_ele.team] == team: p_board[i][k] = -1 * ai_weights.bishop else: p_board[i][k] = ai_weights.bishop piece_names.queen: - if piece[1] == team: + if piece[text_board_ele.team] == team: p_board[i][k] = -1 * ai_weights.queen else: p_board[i][k] = ai_weights.queen piece_names.king: - if piece[1] == team: + if piece[text_board_ele.team] == team: p_board[i][k] = -1 * ai_weights.king else: p_board[i][k] = ai_weights.king else: - p_board[i][k] = 0 + if ! p_board[i][k]: # don't clobber en passant points + p_board[i][k] = 0 return p_board func new_turn(): @@ -251,6 +275,14 @@ enum piece_names { queen } +enum text_board_ele { + piece_enum, + team, + en_passant, + has_moved, + in_check + } + func board_to_text_board(boarde): var text_board = new_board() for i in 8: @@ -409,7 +441,7 @@ func team_every_legal_move(text_board, team): var move_pattern #var name_of_this = match_piece_names_enums(piece_name) move_pattern = get_move_pattern([piece_name, team], coords) - every_legal_move.append([[i,k], can_chess_move(move_pattern, coords, text_board, tile_setting.hide_tiles_no_cover_allies)]) + every_legal_move.append([[i,k, piece_name], can_chess_move(move_pattern, coords, text_board, tile_setting.hide_tiles_no_cover_allies)]) #rint(every_legal_move) return every_legal_move -- cgit v1.2.3