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/Board.qml | 11 ++++++----- qml/pages/Goban.qml | 56 ++++++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/qml/pages/Board.qml b/qml/pages/Board.qml index 27fc319..03fa000 100644 --- a/qml/pages/Board.qml +++ b/qml/pages/Board.qml @@ -15,11 +15,13 @@ Page { Column { + id: column anchors.fill: parent; spacing: 25 Row { + id: row width: parent.width; IconButton { @@ -43,9 +45,9 @@ Page { } Goban { - id:goban - width: parent.width - height: 650 + id: goban; + width: parent.width; + height: column.height - (row.height + view.height); } @@ -59,7 +61,6 @@ Page { model: 5 delegate: Text { horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter color: Theme.primaryColor font.family: Theme.fontFamily @@ -67,7 +68,7 @@ Page { width: view.itemWidth height: view.height - text: "Problem " + index + text: "Problem " + (index + 1); } } 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