2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * The contents of this file are subject to the terms of either the GNU
5 * General Public License Version 2 only ("GPL") or the Common
6 * Development and Distribution License("CDDL") (collectively, the
7 * "License"). You may not use this file except in compliance with the
8 * License. You can obtain a copy of the License at
9 * http://www.netbeans.org/cddl-gplv2.html
10 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
11 * specific language governing permissions and limitations under the
12 * License. When distributing the software, include this License Header
13 * Notice in each file and include the License file at
14 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
15 * particular file as subject to the "Classpath" exception as provided
16 * by Sun in the GPL Version 2 section of the License file that
17 * accompanied this code. If applicable, add the following below the
18 * License Header, with the fields enclosed by brackets [] replaced by
19 * your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Portions Copyrighted 2009 Jaroslav Tulach
26 package cz.xelfi.quoridor;
29 * Represents position and number of available fences of a player on
32 public final class Player extends Object {
36 /** number of fences this player has */
38 /** the direction of players end line */
39 final Direction endDirection;
41 Player(int x, int y, int f, Player.Direction endDir) {
46 this.endDirection = endDir;
49 /** Returns the x-coordinate of the player.
50 * @return number from 0 to 16
56 /** Returns the y-coordinate of the player.
57 * @return number from 0 to 16
63 /** Returns position of the player from 0-8.
65 * @return integer from 0-8
67 public int getColumn() {
71 /** The y-position of the player.
72 * @return integer from 0-8
78 /** How much fences is still available for the player.
80 * @return number of fences this player still has
82 public int getFences() {
87 public String toString() {
88 return "Player[" + getColumn() + "," + getRow() + "," + f + "," + endDirection + "]";
92 public int hashCode() {
93 return 8 * x + 2 * y + 4 * f + 7 + endDirection.hashCode();
97 public boolean equals(Object o) {
98 if (o instanceof Player) {
99 Player p = (Player) o;
100 return x == p.x && y == p.y && f == p.f && endDirection.equals(p.endDirection);
105 /** Possible directions of player's moves.
107 public enum Direction {
109 NORTH('P', 16), WEST((char) -1, -1), EAST((char) -1, -1), SOUTH('Q', 0);
113 private Direction(char ch, int fl) {
118 final boolean reached(Player p) {
119 return p.getYInternal() == finalLine;