From ae56c3788db6ebd02e918fd40ae7f3d75719dd64 Mon Sep 17 00:00:00 2001 From: "Cap. Hindsight" Date: Fri, 24 Feb 2017 19:28:52 +0300 Subject: [PATCH] Add lazy update to play.js --- WebApp/Content/play.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/WebApp/Content/play.js b/WebApp/Content/play.js index c9206e3..cde92e7 100644 --- a/WebApp/Content/play.js +++ b/WebApp/Content/play.js @@ -14,6 +14,45 @@ function reset_move() { $(".square-selected-quantum").removeClass("square-selected-quantum"); } +var prev_chessboard = null; + +function chessboards_equal(a, b) { + if (a == null && b == null) { + return true; + } else if (a == null && b != null) { + return false; + } else if (a != null && b == null) { + return false; + } else { + if (a.gameState != b.gameState) + return false; + if (a.activePlayer != b.activePlayer) + return false; + var rows = "abcdefgh"; + for (var x_i in rows) { + var x = rows[x_i]; + for (var y = 1; y <= 8; y++) { + var pos = x + y; + if (a.squares[pos] == null && b.squares[pos] == null) { + continue; + } else if (a.squares[pos] == null && b.squares[pos] != null) { + return false; + } else if (a.squares[pos] != null && b.squares[pos] == null) { + return false; + } else { + if (a.squares[pos].player != b.squares[pos].player) + return false; + if (a.squares[pos].piece != b.squares[pos].piece) + return false; + if (a.squares[pos].probability != b.squares[pos].probability) + return false; + } + } + } + return true; + } +} + function submit_move() { if (move.middle == move.source || move.middle == move.target) move.middle = ""; @@ -59,6 +98,9 @@ function draw(canvas, data) { function update_chessboard() { var board = $.get(prefix + "/api/game_info", {"gameId": gameId}, function(data) { + if (chessboards_equal(prev_chessboard, data)) + return; + prev_chessboard = data; if (data.gameState != "game_still_going") { $(".chessboard").addClass("game-over"); var message = "???";