Skip to content

Commit

Permalink
Merge pull request #30 from Ivan23BG/update-player-vs-ia
Browse files Browse the repository at this point in the history
On ne peut plus jouer quand l'ia calcule
  • Loading branch information
Bon-Monsieur authored Apr 10, 2024
2 parents 436f905 + 9cb5986 commit e45ce3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def hexiaia_place_piece():
try:
if game_board is not None:

move_IA = game_board.get_best_move(2,current_IA)
move_IA = game_board.get_best_move(3,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
12 changes: 8 additions & 4 deletions src/main/game_ui/static/js/game_hexia.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function fetchFirstMoveJSON() {

// request for IA's move
async function fetchIAMoveJSON(IA) {
console.log("deux");
const response = await fetch('/hexiaia_place_piece', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({'current_IA': IA})});
const data = response.json();
return data;
Expand All @@ -42,7 +43,8 @@ window.onload = async function () {
let player = 0; // Player default value
let IA = 0; // IA default value

let recup_error = false;
let recup_error = false; // Variable qui empêche que l'IA joue si on clic sur un hex pas bon
let playable = true; // Check if player can play or not
let game_over = false;
let short_path = [];
let winner = 0;
Expand Down Expand Up @@ -81,7 +83,8 @@ window.onload = async function () {
// show spinner
document.getElementById('spinner').style.display = 'block';

if (this.getAttribute('disabled')) {

if (this.getAttribute('disabled') || playable===false) {
// hide spinner
document.getElementById('spinner').style.display = 'none';
return;
Expand Down Expand Up @@ -164,15 +167,16 @@ window.onload = async function () {

//Place piece if player doesn't win
if (game_over!=true && recup_error!=true){
const data = await fetchIAMoveJSON(IA); // Get IA's move
playable=false;
const data = await fetchIAMoveJSON(IA); // Get IA's move
let iamove = data.iamove;
console.log(data.iamove);
var iahex = document.getElementById(iamove);
console.log(iahex);

game_history.push(iamove);
toggle_colour(iahex,IA);

playable = true;
// check if current_IA won
if (data.game_over === true) {
winner = IA;
Expand Down

0 comments on commit e45ce3a

Please sign in to comment.