Skip to content

Commit

Permalink
Merge pull request #27 from Ivan23BG/debug-iavsia
Browse files Browse the repository at this point in the history
del interval and add while loops
  • Loading branch information
Bon-Monsieur authored Apr 10, 2024
2 parents 03507d7 + 5228edb commit 18872b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def hex_place_piece_ia():
#IA's turn
IA = 3 - player
# make a move using minimax algorithm and get_best_move method (actualy random move)
move = game_board.get_best_move(3,IA)
move = game_board.get_best_move(2,IA)
game_board.place_piece(IA, move)


Expand Down Expand Up @@ -170,7 +170,7 @@ def hexiaia_place_piece():
try:
if game_board is not None:

move_IA = game_board.get_best_move(3,current_IA)
move_IA = game_board.get_best_move(2,current_IA)
game_board.place_piece(current_IA, move_IA) # Try to place the piece
iamove = "hex" + str(move_IA[0]) + "-" + str(move_IA[1])

Expand Down
13 changes: 7 additions & 6 deletions src/main/game_ui/static/js/game_hexiaia.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ window.onload = async function () {
let game_over = false;
let short_path = [];
let winner = 0;
let stopped = false;

const game_history = []; // stack to store game_history
const cells = document.querySelectorAll('.hex'); // Get all hex cells

let jeu = setInterval(async () => { // Boucle du jeu

while(!stopped){
const data = await fetchIAMoveJSON(current_IA); // Get current_IA's move
let iamove = data.iamove;
var iahex = document.getElementById(iamove);
Expand All @@ -36,9 +36,7 @@ window.onload = async function () {
winner = current_IA;
short_path = data.hexid;
game_over = true;

// Stop the game
clearInterval(jeu);
stopped=true;

// Display winning path when game is over
let k = 0;
Expand All @@ -55,7 +53,9 @@ window.onload = async function () {
else{
current_IA = current_IA === 1 ? 2 : 1;
}
}, 50); // Game speed = 50
}


// End of jeu


Expand Down Expand Up @@ -84,6 +84,7 @@ window.onload = async function () {
hex.style.backgroundColor = '#B0BFB1';
});
game_over = false;
current_IA = 1;
} // end of reset_board

}
Expand Down

0 comments on commit 18872b5

Please sign in to comment.