X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FGame.vue;h=00414d9136469758b6d339327d7fcb17d3d7d9a3;hp=262823dfffbdf8873979e6ad2eb65684f803fbcd;hb=72ccbd6730241771e6ba86b6a5b62597b4c7e2f4;hpb=5701c228a422bed7570452b2d24b3193f7653a19 diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index 262823df..00414d91 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -48,6 +48,7 @@ export default { drawOffer: "", //TODO: use for button style people: [], //players + observers lastate: undefined, //used if opponent send lastate before game is ready + repeat: {}, //detect position repetition }; }, watch: { @@ -407,6 +408,7 @@ export default { oppid: (myIdx < 0 ? undefined : game.players[1-myIdx].uid), } ); + this.repeat = {}; //reset if (!!this.lastate) //lastate arrived before game was loaded: this.processLastate(); callback(); @@ -505,6 +507,16 @@ export default { //TODO: (Vue3) just this.game.clocks[colorIdx] += addTime; this.$set(this.game.clocks, colorIdx, this.game.clocks[colorIdx] + addTime); this.game.initime[nextIdx] = Date.now(); + // If repetition detected, consider that a draw offer was received: + const fenObj = V.ParseFen(move.fen); + let repIdx = fenObj.position + "_" + fenObj.turn; + if (!!fenObj.flags) + repIdx += "_" + fenObj.flags; + this.repeat[repIdx] = (!!this.repeat[repIdx] + ? this.repeat[repIdx]+1 + : 1); + if (this.repeat[repIdx] >= 3) + this.drawOffer = "received"; //TODO: will print "mutual agreement"... }, gameOver: function(score) { this.game.mode = "analyze"; @@ -521,5 +533,15 @@ export default {