From 9c9402c3bbc4b1ab0fc91a0bca4302e82d6936e5 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 1 Dec 2023 14:57:08 +0100 Subject: [PATCH] =?UTF-8?q?les=20bots=20peuvent=20jouer=20apr=C3=A8s=20que?= =?UTF-8?q?=20quelqu'un=20ait=20quitt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 16 ++++--- .../src/Components/GraphContainer.tsx | 46 +++++++++++-------- .../src/Components/PersonStatus.tsx | 1 + 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index 55d91e9..6d3511d 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -145,15 +145,17 @@ io.on('connection', (socket) => { }) socket.on("who plays", (room) => { - let player = map.get(room).actualPlayer - if (map.get(room).tab[player].type != "User"){ - player = player + 1 - if (player == map.get(room).tab.length){ - player=0 + if (map.get(room) !== undefined){ + let player = map.get(room).actualPlayer + if (map.get(room).tab[player].type != "User"){ + player = player + 1 + if (player == map.get(room).tab.length){ + player=0 + } } + console.log(player) + io.to(room).emit("who plays", player, map.get(room).lastWorks) } - console.log(player) - io.to(room).emit("who plays", player, map.get(room).lastWorks) }) socket.on("disconnect", () =>{ diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 8091f35..af55ca0 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -61,6 +61,7 @@ let cptPlayerLeft = 0 let firstPlayer = 0 let cptBug = 0 let cptUseEffect = 0 +let testPlayers: Player[] = [] const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => { @@ -102,8 +103,14 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }, [elapsedTime, endgame]); + useEffect(() => { + testPlayers = players + console.log(testPlayers) + }, [players]) + useEffect(() =>{ touchedPlayer=playerTouched + console.log(playerTouched) if (touchedPlayer == -1){ if (!askedWrongLocal){ socket.emit("put correct background", socket.id) @@ -157,7 +164,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS useEffect(() =>{ cptBug=0 if (actualPlayerIndex==firstPlayer){ - const bot = players[lastIndex] + const bot = testPlayers[lastIndex] if(bot instanceof Bot && botIndex != lastIndex){ botIndex = lastIndex if (personNetwork!=null){ @@ -181,7 +188,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } const tester = IndiceTesterFactory.Create(indices[playerIndex]) const works = tester.Works(person) - socket.emit("asked all 1by1", person.getId(), players[playerIndex].id) + socket.emit("asked all 1by1", person.getId(), testPlayers[playerIndex].id) if (i==players.length){ socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) } @@ -190,7 +197,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } if(!works){ socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) - const ind = bot.placeSquare(personNetwork, players) + const ind = bot.placeSquare(personNetwork, testPlayers) if (ind == -1 ){ socket.emit("can't put square", lastIndex, room) return @@ -209,7 +216,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } else{ if (person!=undefined){ - if (players[choosedPlayerIndex] instanceof Bot){ + if (testPlayers[choosedPlayerIndex] instanceof Bot){ console.log("BOT") const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) const works = tester.Works(person) @@ -224,7 +231,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS else{ console.log(lastIndex + " interroge " + choosedPlayerIndex + " a propos de " + person.getName() + " et dit non") socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex) - const ind = bot.placeSquare(personNetwork, players) + const ind = bot.placeSquare(personNetwork, testPlayers) if (ind == -1 ){ socket.emit("can't put square", playerIndex, room) return @@ -239,11 +246,11 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } else{ console.log(choosedPlayerIndex + " => Pas bot" ) - socket.emit("ask player", personIndex, players[choosedPlayerIndex].id, players[lastIndex]) + socket.emit("ask player", personIndex, testPlayers[choosedPlayerIndex].id, testPlayers[lastIndex]) console.log(lastIndex + " interroge " + +choosedPlayerIndex + " sur " + personNetwork.getPersons()[personIndex].getName()) const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) if (!tester.Works(person)){ - const ind = bot.placeSquare(personNetwork, players) + const ind = bot.placeSquare(personNetwork, testPlayers) if (ind == -1 ){ socket.emit("can't put square", playerIndex, room) return @@ -382,7 +389,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS tmpTab.push(JSONParser.JSONToPlayer(p)) } else{ - tmpTab.push(players[ind]) + tmpTab.push(testPlayers[ind]) } ind ++ } @@ -399,12 +406,11 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS tmpTab.push(JSONParser.JSONToPlayer(p)) } else{ - tmpTab.push(players[ind]) + tmpTab.push(testPlayers[ind]) } ind ++ } if (i==firstPlayer){ - console.log(tmpTab) for(let index = 0; index < tmpTab.length; index++){ const test = tmpTab[index] if (test instanceof User){ @@ -508,7 +514,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS if (p!=undefined && tab != undefined){ tab.push(p) if (actualPlayerIndex == 0){ - players.forEach((player) => { + testPlayers.forEach((player) => { if (player instanceof Bot){ player.newInformation(p, askedIndex, works) } @@ -522,7 +528,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS cptHistory++ if (cptHistory % 2 == 0){ lastNodes.push(node) - addToHistory(players[askedIndex].pseudo + " à mis un " + positionToEmoji(askedIndex, works) + " à " + personNetwork.getPersons()[id].getName()) + addToHistory(testPlayers[askedIndex].pseudo + " à mis un " + positionToEmoji(askedIndex, works) + " à " + personNetwork.getPersons()[id].getName()) } } @@ -584,7 +590,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS cptBug=0 cptOnAskedWrong ++ if (cptOnAskedWrong % 2 == 0){ - addToHistory(players[askingPlayer].pseudo + " ne peut plus poser de carré") + addToHistory(testPlayers[askingPlayer].pseudo + " ne peut plus poser de carré") playerIndex = askingPlayer + 1 if(playerIndex == players.length){ playerIndex = 0 @@ -629,8 +635,8 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.emit("node checked", nodeId, true, actualPlayerIndex, room, playerIndex) } else{ - let index = players.findIndex((p) => p.id == askingPlayer.id) - if (players[index] instanceof Bot){ + let index = testPlayers.findIndex((p) => p.id == askingPlayer.id) + if (testPlayers[index] instanceof Bot){ index = playerIndex + 1 if(index == players.length){ index = 0 @@ -816,9 +822,9 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS network.on("click", async (params) => { if(params.nodes.length > 0){ - console.log(actualPlayerIndex + " => " + playerIndex) - console.log(playerTouched) + console.log(touchedPlayer) setNodeIdData(params.nodes[0]) + console.log(players) // addToHistory("Le joueur a cliqué") //! TEST DEBUG if (!solo){ if (askedWrongLocal){ @@ -848,7 +854,9 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } else if(touchedPlayer != -1 && playerIndex == actualPlayerIndex && touchedPlayer = ({onNodeClick, handleS } else{ if (touchedPlayer >= 0){ - console.log(touchedPlayer) + console.log("CE N'EST PAS UN BOT") //@ts-ignore socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex)) socket.emit("put correct background", socket.id) diff --git a/cryptide_project/src/Components/PersonStatus.tsx b/cryptide_project/src/Components/PersonStatus.tsx index 7ec2942..4bf7415 100644 --- a/cryptide_project/src/Components/PersonStatus.tsx +++ b/cryptide_project/src/Components/PersonStatus.tsx @@ -51,6 +51,7 @@ const PersonStatus: React.FC = ({img = Person, state= Person, function onTouch(){ if (IsActualPlayer && !askedWrong){ setPlayerTouched(index) + setTouchedPlayer(index) } }