2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
18 package cz.xelfi.quoridor;
21 * Represents position of a fence on a {@link Board}. The fence can be oriented
23 * {@link Orientation#HORIZONTAL} or {@link Orientation#VERTICAL} direction.
24 * The faces postions are numbered 1-8 and A-H according to following
28 +-----------------------------------+
30 1--| + + + + + + + + |--1
32 2--| + + + + + + + + |--2
34 3--| + + + + + + + + |--3
36 4--| + + + + + + + + |--4
38 5--| + + + + + + + + |--5
40 6--| + + + + + + + + |--6
42 7--| + + + + + + + + |--7
44 8--| + + + + + + + + |--8
46 +-----------------------------------+
52 public final class Fence extends Object {
56 private final Orientation o;
58 Fence(int x, int y, Orientation o) {
65 /** The column of the center of the fence. The same
66 * as used in {@link Move#fence(char, int, cz.xelfi.quoridor.Fence.Orientation)}.
68 * @return a letter between 'A' and 'H'
70 public char getColumn() {
71 return (char) ('A' + (x - 1) / 2);
74 /** The row of the center of the fence. The same
75 * as specified in {@link Move#fence(char, int, cz.xelfi.quoridor.Fence.Orientation)}.
77 * @return a number between 1 and 8
83 /** Midle coordinate of the fence.
90 /** Midle coordinate of the fence.
97 /** The orientation of the fence.
99 * @return HORIZONTAL or VERTICAL
101 public Orientation getOrientation() {
106 public String toString() {
107 return "Fence[" + getColumn() + "," + getRow() + "," + o + "]";
111 public int hashCode() {
112 return 8 * x + 4 * y + 13 + o.hashCode();
116 public boolean equals(Object o) {
117 if (o instanceof Fence) {
119 return x == f.x && y == f.y && getOrientation().equals(f.getOrientation());
124 /** The possible orientation of a {@link Fence}.
125 * Either horizontal of vertical.
127 public static enum Orientation {
128 HORIZONTAL, VERTICAL;
130 private Orientation() {