From f50c3cfac4ae07f819b9c9905b42e0ded306e0a0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 28 Aug 2014 21:30:43 +0200 Subject: Do not allow suicide --- qml/pages/Goban.qml | 56 ++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'qml/pages/Goban.qml') diff --git a/qml/pages/Goban.qml b/qml/pages/Goban.qml index f84bb60..0dee0c8 100644 --- a/qml/pages/Goban.qml +++ b/qml/pages/Goban.qml @@ -103,8 +103,6 @@ Item { || (!limitTop && Actions.isFirstRow(index, goban.columns)) || (!limitBottom && Actions.isLastRow(index, goban.columns, goban.rows)) ) { - console.log("click outside", index, goban.rows, Actions.isFirstRow(index, goban.columns)); - return; } @@ -125,29 +123,27 @@ Item { return repeater.itemAt(x).getType() === (currentPlayer ? "black" : "white"); } - /* - * Check for pieces to remove. - */ - var toRemove = neighbors.filter(isOponnent); + function freeOrChain(x) { + var pointType = repeater.itemAt(x).getType(); + return pointType === "" || pointType === (currentPlayer ? "white" : "black"); + } -// function freeOrChain(x) { -// var pointType = repeater.itemAt(x).getType(); -// return pointType === "" || pointType === (currentPlayer ? "white" : "black"); -// } -// /* -// * Single suicide is not allowed… -// */ -// if (neighbors.length !== 0 && toRemove.length === 0 && !neighbors.some(freeOrChain)) { -// return; -// } + if (neighbors.length !== 0) { - point.put(currentPlayer, true); + var somethingToRemove = false; - if (neighbors.length !== 0) { + point.put(currentPlayer, true); + + /* + * Check for pieces to remove. + */ + neighbors.filter(isOponnent).forEach(function(neighbor) { - toRemove.forEach(function(neighbor) { - Actions.getChainToRemove(neighbor, repeater, goban.columns, goban.rows, isOponnent). - forEach(function(x) { + var piecesToRemove = Actions.getChainToRemove(neighbor, repeater, goban.columns, goban.rows, isOponnent); + if (piecesToRemove.length !== 0) { + somethingToRemove = true; + } + piecesToRemove.forEach(function(x) { repeater.itemAt(x).remove(true); }) }); @@ -155,10 +151,17 @@ Item { /* * Check for suicide. */ - Actions.getChainToRemove(index, repeater, goban.columns, goban.rows, isPlayer). - forEach(function(x) { - repeater.itemAt(x).remove(true); - }); + if (!somethingToRemove) { + var suicides = Actions.getChainToRemove(index, repeater, goban.columns, goban.rows, isPlayer); + if (suicides.length !== 0) { +// suicides.forEach(function(x) { +// repeater.itemAt(x).remove(true); +// }); + point.remove(false); + currentPlayer = !currentPlayer; + } + + } /* * Remove the marks in the cases. @@ -173,7 +176,6 @@ Item { for (var i = 0; i < goban.columns * goban.rows; i++) { repeater.itemAt(i).mark = false; } - } currentPlayer = !currentPlayer; @@ -203,7 +205,9 @@ Item { width: goban.width - caseSize; color: "black" + visible: (!((index === goban.rows - 1 && !limitBottom) || (index === 0 && !limitTop))) + height: 1 } -- cgit v1.2.3