This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
957 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Suji | ||
[![Build Status](https://travis-ci.org/GoSuji/Suji.svg?branch=master)](https://travis-ci.org/GoSuji/Suji) [![Coverage Status](https://coveralls.io/repos/github/GoSuji/Suji/badge.svg?branch=master)](https://coveralls.io/github/GoSuji/Suji?branch=master) | ||
|
||
The Suji Go Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2017 Vincent Varkevisser | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package logic; | ||
|
||
import util.Coords; | ||
|
||
import java.util.Set; | ||
|
||
public class Board { | ||
private ChainSet blackStones; | ||
private ChainSet whiteStones; | ||
|
||
public Board() { | ||
blackStones = new ChainSet(); | ||
whiteStones = new ChainSet(); | ||
} | ||
|
||
public final Set<Coords> getBlackStones() { | ||
return blackStones.getStones(); | ||
} | ||
|
||
public final Set<Coords> getWhiteStones() { | ||
return whiteStones.getStones(); | ||
} | ||
|
||
public void playBlackStone(Coords coords) { | ||
throwIfOccupied(coords); | ||
|
||
blackStones.add(coords); | ||
} | ||
|
||
public void playWhiteStone(Coords coords) { | ||
throwIfOccupied(coords); | ||
|
||
whiteStones.add(coords); | ||
} | ||
|
||
public boolean isLegalWhiteMove(Coords coords) { | ||
return !isOccupied(coords); | ||
} | ||
|
||
public boolean isLegalBlackMove(Coords coords) { | ||
return !isOccupied(coords); | ||
} | ||
|
||
|
||
private void throwIfOccupied(Coords coords) { | ||
if (isOccupied(coords)) | ||
throw new IllegalArgumentException(coords.toString() + " is already occupied."); | ||
} | ||
|
||
private boolean isOccupied(Coords coords) { | ||
return blackStones.contains(coords) || whiteStones.contains(coords); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (C) 2017 Vincent Varkevisser | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package logic; | ||
|
||
import util.Coords; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Chain { | ||
private HashSet<Coords> stones; | ||
private HashSet<Coords> liberties; | ||
|
||
Chain(Coords coords) { | ||
stones = new HashSet<>(); | ||
|
||
stones.add(coords); | ||
recalculateLiberties(); | ||
} | ||
|
||
private void recalculateLiberties() { | ||
liberties = new HashSet<>(); | ||
|
||
for (Coords stone : stones) { | ||
Set<Coords> neighbours = stone.getNeighbours(); | ||
|
||
for (Coords c : neighbours) | ||
if (!this.contains(c)) | ||
liberties.add(c); | ||
} | ||
} | ||
|
||
protected boolean contains(Coords stone) { | ||
return stones.contains(stone); | ||
} | ||
|
||
protected HashSet<Coords> getLiberties() { | ||
return liberties; | ||
} | ||
|
||
protected boolean isAdjacentTo(Coords coords) { | ||
return liberties.contains(coords); | ||
} | ||
|
||
protected boolean isAdjacentTo(Chain other) { | ||
for (Coords lib : liberties) | ||
if (other.contains(lib)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
protected int size() { | ||
return stones.size(); | ||
} | ||
|
||
private void clear() { | ||
stones.clear(); | ||
liberties.clear(); | ||
} | ||
|
||
protected int countLiberties() { | ||
return liberties.size(); | ||
} | ||
|
||
protected void mergeChain(Chain other) { | ||
if (!isAdjacentTo(other)) | ||
throw new IllegalArgumentException("Chains are not adjacent and cannot be merged."); | ||
|
||
stones.addAll(other.stones); | ||
|
||
other.clear(); | ||
|
||
recalculateLiberties(); | ||
} | ||
|
||
protected Set<Coords> getStones() { | ||
return stones; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2017 Vincent Varkevisser | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package logic; | ||
|
||
import util.Coords; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class ChainSet { | ||
private HashMap<Chain, Integer> chains; | ||
|
||
public ChainSet() { | ||
chains = new HashMap<>(); | ||
} | ||
|
||
public boolean contains(Coords stone) { | ||
for (Chain chain : chains.keySet()) | ||
if (chain.contains(stone)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
public Set<Coords> getStones() { | ||
Set<Coords> stones = new HashSet<>(); | ||
|
||
for (Chain chain : chains.keySet()) | ||
stones.addAll(chain.getStones()); | ||
|
||
return stones; | ||
} | ||
|
||
public void add(Coords stone) { | ||
addChain(new Chain(stone)); | ||
} | ||
|
||
private void addChain(Chain chain) { | ||
for (Chain existing : chains.keySet()) | ||
if (existing.isAdjacentTo(chain)) { | ||
existing.mergeChain(chain); | ||
return; | ||
} | ||
|
||
chains.put(chain, chain.countLiberties()); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (C) 2017 Vincent Varkevisser | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ui; | ||
|
||
import javafx.beans.value.ChangeListener; | ||
import javafx.fxml.Initializable; | ||
import javafx.scene.canvas.Canvas; | ||
import javafx.scene.canvas.GraphicsContext; | ||
import javafx.scene.input.MouseEvent; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.paint.Color; | ||
import javafx.util.Pair; | ||
import logic.Board; | ||
|
||
import java.net.URL; | ||
import java.util.ResourceBundle; | ||
|
||
public class BoardController implements Initializable { | ||
public Canvas boardCanvas; | ||
public Pane pane; | ||
private Board board; | ||
|
||
public BoardController() { | ||
board = new Board(); | ||
} | ||
|
||
public void canvasClicked(MouseEvent mouseEvent) { | ||
drawBoard(); | ||
} | ||
|
||
private void resizeCanvas() { | ||
boardCanvas.setHeight(pane.getHeight()); | ||
boardCanvas.setWidth(pane.getWidth()); | ||
} | ||
|
||
private void drawBoard() { | ||
drawBackground(); | ||
drawBoardTexture(getTopLeftCorner()); | ||
drawBoardLines(); | ||
drawStones(); | ||
} | ||
|
||
private void drawBoardTexture(Pair<Double, Double> topLeft) { | ||
GraphicsContext context = boardCanvas.getGraphicsContext2D(); | ||
double length = getBoardLength(); | ||
|
||
context.setFill(Color.web("0xB78600")); | ||
context.fillRect(topLeft.getKey(), topLeft.getValue(), length, length); | ||
} | ||
|
||
private void drawBackground() { | ||
GraphicsContext context = boardCanvas.getGraphicsContext2D(); | ||
|
||
context.setFill(Color.GREEN); | ||
context.fillRect(0, 0, boardCanvas.getWidth(), boardCanvas.getHeight()); | ||
} | ||
|
||
private void drawBoardLines() { | ||
|
||
} | ||
|
||
private void drawStones() { | ||
|
||
} | ||
|
||
private double getBoardLength() { | ||
double canvasWidth = boardCanvas.getWidth(); | ||
double canvasHeight = boardCanvas.getHeight(); | ||
|
||
return Math.min(canvasHeight, canvasWidth); | ||
} | ||
|
||
private Pair<Double, Double> getTopLeftCorner() { | ||
double length = getBoardLength(); | ||
double canvasWidth = boardCanvas.getWidth(); | ||
double canvasHeight = boardCanvas.getHeight(); | ||
|
||
double x = 0; | ||
double y = 0; | ||
|
||
if (canvasWidth > length) | ||
x = (canvasWidth - length) / 2; | ||
else | ||
y = (canvasHeight - length) / 2; | ||
|
||
return new Pair<>(x, y); | ||
} | ||
|
||
@Override | ||
public void initialize(URL url, ResourceBundle resourceBundle) { | ||
ChangeListener<Number> paneChangeListener = (observableValue, number, t1) -> { | ||
resizeCanvas(); | ||
drawBoard(); | ||
}; | ||
pane.widthProperty().addListener(paneChangeListener); | ||
pane.heightProperty().addListener(paneChangeListener); | ||
|
||
drawBoard(); | ||
} | ||
} |
Oops, something went wrong.