Les bots ne peuvent plus le faire non plus

demo_bourges
Thomas Chazot 1 year ago
parent e1e7d6ef5c
commit cb2e6570e3

@ -173,6 +173,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
if(!works){ if(!works){
socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex)
const ind = bot.placeSquare(personNetwork, players) const ind = bot.placeSquare(personNetwork, players)
if (ind == -1 ){
addToHistory(lastIndex.toString() + "177")
socket.emit("can't put square", lastIndex, room)
return
}
console.log(lastIndex + " pose carré sur " + personNetwork.getPersons()[ind].getName()) console.log(lastIndex + " pose carré sur " + personNetwork.getPersons()[ind].getName())
playerIndex = lastIndex + 1 playerIndex = lastIndex + 1
if(playerIndex == players.length){ if(playerIndex == players.length){
@ -203,6 +208,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
console.log(lastIndex + " interroge " + choosedPlayerIndex + " a propos de " + person.getName() + " et dit non") console.log(lastIndex + " interroge " + choosedPlayerIndex + " a propos de " + person.getName() + " et dit non")
socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex) socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex)
const ind = bot.placeSquare(personNetwork, players) const ind = bot.placeSquare(personNetwork, players)
if (ind == -1 ){
addToHistory(lastIndex.toString() + "212")
socket.emit("can't put square", playerIndex, room)
return
}
console.log(lastIndex + " pose carré sur " + personNetwork.getPersons()[ind].getName()) console.log(lastIndex + " pose carré sur " + personNetwork.getPersons()[ind].getName())
playerIndex = lastIndex + 1 playerIndex = lastIndex + 1
if(playerIndex == players.length){ if(playerIndex == players.length){
@ -218,6 +228,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex])
if (!tester.Works(person)){ if (!tester.Works(person)){
const ind = bot.placeSquare(personNetwork, players) const ind = bot.placeSquare(personNetwork, players)
if (ind == -1 ){
addToHistory(lastIndex.toString() + "232")
socket.emit("can't put square", playerIndex, room)
return
}
console.log(lastIndex + " pose carré sur " + personNetwork.getPersons()[ind].getName()) console.log(lastIndex + " pose carré sur " + personNetwork.getPersons()[ind].getName())
playerIndex = lastIndex + 1 playerIndex = lastIndex + 1
if(playerIndex == players.length){ if(playerIndex == players.length){
@ -449,6 +464,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
playerIndex = 0 playerIndex = 0
} }
setPlayerIndex(playerIndex) setPlayerIndex(playerIndex)
setLastIndex(playerIndex)
if (playerIndex === actualPlayerIndex){ if (playerIndex === actualPlayerIndex){
handleTurnBarTextChange("À vous de jouer") handleTurnBarTextChange("À vous de jouer")
handleShowTurnBar(true) handleShowTurnBar(true)
@ -476,7 +492,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
const node = nodes.get().find((n) => nodeId == n.id) const node = nodes.get().find((n) => nodeId == n.id)
if (node != undefined && indice != null){ if (node != undefined && indice != null){
var tester = IndiceTesterFactory.Create(indice) var tester = IndiceTesterFactory.Create(indice)
let maybe = actualPlayerIndex
if (tester.Works(pers)){ if (tester.Works(pers)){
playerIndex = playerIndex + 1 playerIndex = playerIndex + 1
if(playerIndex == players.length){ if(playerIndex == players.length){
@ -485,10 +500,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
socket.emit("node checked", nodeId, true, actualPlayerIndex, room, playerIndex) socket.emit("node checked", nodeId, true, actualPlayerIndex, room, playerIndex)
} }
else{ else{
maybe = actualPlayerIndex - 1
if(maybe == 0){
maybe = players.length - 1
}
let index = players.findIndex((p) => p.id == askingPlayer.id) let index = players.findIndex((p) => p.id == askingPlayer.id)
if (players[index] instanceof Bot){ if (players[index] instanceof Bot){
index = playerIndex + 1 index = playerIndex + 1
@ -531,7 +542,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
const tab = mapIndexPersons.get(player) const tab = mapIndexPersons.get(player)
if (tab != undefined){ if (tab != undefined){
if (player != actualPlayerIndex){ if (player != actualPlayerIndex){
console.log("player != actualPlayerIndex")
for(const person of personNetwork.getPersons().filter((p) => tab.includes(p))){ for(const person of personNetwork.getPersons().filter((p) => tab.includes(p))){
networkData.nodes.update({id: person.getId(), color: "#808080"}) networkData.nodes.update({id: person.getId(), color: "#808080"})
} }
@ -559,7 +569,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
socket.on("put imossible grey", ()=>{ socket.on("put imossible grey", ()=>{
if (personNetwork != null && indice!=null){ if (personNetwork != null && indice!=null){
console.log("impossible grey")
const tabNodes: any = [] const tabNodes: any = []
const tester = IndiceTesterFactory.Create(indice) const tester = IndiceTesterFactory.Create(indice)
for (const pers of personNetwork.getPersons()){ for (const pers of personNetwork.getPersons()){
@ -655,7 +664,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
} }
if (a==indices.length){ if (a==indices.length){
//networkData.nodes.update({id: p.getId(), label: p.getName() + "\n🔵"}) //networkData.nodes.update({id: p.getId(), label: p.getName() + "\n🔵"})
console.log(p) //console.log(p)
} }
}); });

@ -98,6 +98,9 @@ class EasyBot extends Bot{
tabFilterPerson.push(p) tabFilterPerson.push(p)
} }
}) })
if (tabFilterPerson.length == 0){
return -1
}
return tabFilterPerson[Math.floor(Math.random() * tabFilterPerson.length)].getId() return tabFilterPerson[Math.floor(Math.random() * tabFilterPerson.length)].getId()
} }

Loading…
Cancel
Save