Skip to content

Commit

Permalink
Merge pull request #8 from easychessanimations/master
Browse files Browse the repository at this point in the history
Make confirming draw offer optional and auto draw threefold repetition
  • Loading branch information
RaviharaV-bot committed Jan 13, 2022
2 parents be54f7e + 4cdc0c5 commit 03fc9c9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
20 changes: 20 additions & 0 deletions client/boardSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BoardSettings {
constructor() {
this.settings = {};
this.settings["animation"] = new AnimationSettings(this);
this.settings["confirmdraw"] = new ConfirmDrawSettings(this);
this.settings["showDests"] = new ShowDestsSettings(this);
this.settings["autoPromote"] = new AutoPromoteSettings(this);
this.settings["arrow"] = new ArrowSettings(this);
Expand Down Expand Up @@ -120,6 +121,8 @@ class BoardSettings {

settingsList.push(this.settings["animation"].view());

settingsList.push(this.settings["confirmdraw"].view());

settingsList.push(this.settings["showDests"].view());

if (variant.autoPromoteable)
Expand Down Expand Up @@ -207,6 +210,23 @@ class AnimationSettings extends BooleanSettings {
}
}

class ConfirmDrawSettings extends BooleanSettings {
readonly boardSettings: BoardSettings;

constructor(boardSettings: BoardSettings) {
super('confirmdraw', true);
this.boardSettings = boardSettings;
}

update(): void {

}

view(): VNode {
return h('div', checkbox(this, 'confirmdraw', _("Confirm draw offer")));
}
}

class BoardStyleSettings extends NumberSettings {
readonly boardSettings: BoardSettings;
readonly boardFamily: string;
Expand Down
20 changes: 18 additions & 2 deletions client/roundCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Pos } from "@publishvue/chessopsnpmts"
function isCheck(fen:string):boolean{
const pos = Pos().setVariant("atomic").setFen(fen)
const check = pos.checkedKingUci() !== ""
console.log(fen, check)
//console.log(fen, check)
return check
}

Expand Down Expand Up @@ -545,7 +545,8 @@ export default class RoundController {

private draw = () => {
// console.log("Draw");
if (confirm(_('Are you sure you want to draw?'))) {
const doOfferDraw = ( localStorage.getItem("confirmdraw") === "false" ) || confirm(_('Are you sure you want to draw?'))
if (doOfferDraw) {
this.doSend({ type: "draw", gameId: this.gameId });
this.setDialog(_("Draw offer sent"));
}
Expand Down Expand Up @@ -1147,6 +1148,21 @@ export default class RoundController {
return (orig: cg.Key, dest: cg.Key, capturedPiece: cg.Piece) => {
console.log(" ground.onMove()", orig, dest, capturedPiece);
sound.moveSound(this.variant, !!capturedPiece);

const currFen = this.steps[this.steps.length - 1].fen.split(" ").slice(0, 4).join(" ")

let fenCnt = 0

for(let i = 0;i<this.steps.length;i++){
if(this.steps[i].fen.split(" ").slice(0,4).join(" ") === currFen) fenCnt++
}

//console.log(currFen, "occured", fenCnt)

if(fenCnt >= 3){
console.log("requesting draw on threefold")
this.doSend({ type: "draw", gameId: this.gameId });
}
}
}

Expand Down

0 comments on commit 03fc9c9

Please sign in to comment.