Renaming the getX/Y to internal as it uses 0-16 positions
authorJaroslav Tulach <jtulach@netbeans.org>
Thu, 28 May 2009 23:26:50 +0200
changeset 26549ff1a27eff
parent 25 f27d4c4cd464
child 27 77ddbc4ecf78
Renaming the getX/Y to internal as it uses 0-16 positions
quoridor/src/main/java/cz/xelfi/quoridor/Board.java
quoridor/src/main/java/cz/xelfi/quoridor/Player.java
quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java
     1.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Board.java	Mon May 25 09:07:15 2009 +0200
     1.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Board.java	Thu May 28 23:26:50 2009 +0200
     1.3 @@ -238,7 +238,7 @@
     1.4  
     1.5          // straight jump over
     1.6          for (Player p : players) {
     1.7 -            if (p.getX () == oneStep.getX () && p.getY() == oneStep.getY ()) {
     1.8 +            if (p.getXInternal () == oneStep.getXInternal () && p.getYInternal() == oneStep.getYInternal ()) {
     1.9                  // ok, we are jumping over this one
    1.10                  GO_ON: if (where[0] != where[1]) {
    1.11                      // first of all ensure that we cannot go straight
    1.12 @@ -268,7 +268,7 @@
    1.13          
    1.14          int index = players.indexOf (player);
    1.15          Player[] arr = players.toArray (new Player[0]);
    1.16 -        arr[index] = new Player (arr[index].getX (), arr[index].getY (), arr[index].getFences () - 1, arr[index].endDirection);
    1.17 +        arr[index] = new Player (arr[index].getXInternal(), arr[index].getYInternal(), arr[index].getFences() - 1, arr[index].endDirection);
    1.18          
    1.19          HashSet<Fence> fen = new HashSet<Fence> (this.fences);
    1.20          fen.add (fence);
    1.21 @@ -379,7 +379,7 @@
    1.22          List<Player> arr = new ArrayList<Player>(2);
    1.23          assert p != null;
    1.24          int southFences = lastMatcher.end(2) - lastMatcher.start(2);
    1.25 -        arr.add(new Player(p.getX(), p.getY(), southFences, p.endDirection));
    1.26 +        arr.add(new Player(p.getXInternal(), p.getYInternal(), southFences, p.endDirection));
    1.27          arr.add(q);
    1.28          int turn = "*".equals(lastMatcher.group(3)) ? 0 : 1; // NOI18N
    1.29          return new Board(turn, arr, fences);
    1.30 @@ -464,8 +464,8 @@
    1.31  
    1.32          {
    1.33              for (Player p : players) {
    1.34 -                int px = p.getX() / 2;
    1.35 -                int py = p.getY() / 2;
    1.36 +                int px = p.getXInternal() / 2;
    1.37 +                int py = p.getYInternal() / 2;
    1.38                  desk
    1.39                      [1 + py * (spaceY + 1) + spaceY / 2]
    1.40                      [1 + px * (spaceX + 1) + spaceX / 2] = p.endDirection.player;
    1.41 @@ -623,16 +623,16 @@
    1.42          
    1.43          switch (endDir) {
    1.44              case NORTH: 
    1.45 -                if (position.getY () == 8) return true;
    1.46 +                if (position.getYInternal() == 8) return true;
    1.47                  break;
    1.48              case SOUTH:
    1.49 -                if (position.getY () == 0) return true;
    1.50 +                if (position.getYInternal() == 0) return true;
    1.51                  break;
    1.52              case EAST:
    1.53 -                if (position.getX () == 0) return true;
    1.54 +                if (position.getXInternal() == 0) return true;
    1.55                  break;
    1.56              case WEST:
    1.57 -                if (position.getX () == 8) return true;
    1.58 +                if (position.getXInternal() == 8) return true;
    1.59                  break;
    1.60              default:
    1.61                  throw new IllegalStateException ("Wrong direction: " + endDir); // NOI18N
    1.62 @@ -661,8 +661,8 @@
    1.63          BitSet occupied = new BitSet (20 * 30); // TBD this is just an upper guess
    1.64          
    1.65          for (Player p : players) {
    1.66 -            if (p.getX () % 2 == 1) throw new IllegalPositionException ("Wrong player position: " + p); // NOI18N
    1.67 -            if (p.getY () % 2 == 1) throw new IllegalPositionException ("Wrong player position: " + p); // NOI18N
    1.68 +            if (p.getXInternal() % 2 == 1) throw new IllegalPositionException ("Wrong player position: " + p); // NOI18N
    1.69 +            if (p.getYInternal() % 2 == 1) throw new IllegalPositionException ("Wrong player position: " + p); // NOI18N
    1.70              
    1.71              int index = toIndex (p);
    1.72              if (occupied.get (index)) {
    1.73 @@ -693,7 +693,7 @@
    1.74      /** Converts twodimensional coordinates of player to one dimensional index.
    1.75       */
    1.76      private static int toIndex (Player p) {
    1.77 -        return toIndex (p.getX (), p.getY ());
    1.78 +        return toIndex (p.getXInternal(), p.getYInternal());
    1.79      }
    1.80      
    1.81      /** Converts twodimensional coordinates of fence to one dimensional index.
     2.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Player.java	Mon May 25 09:07:15 2009 +0200
     2.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Player.java	Thu May 28 23:26:50 2009 +0200
     2.3 @@ -47,22 +47,24 @@
     2.4      }
     2.5  
     2.6      /** Returns the x-coordinate of the player.
     2.7 -     * @return  number from 0 to 8
     2.8 +     * @return  number from 0 to 16
     2.9       */
    2.10 -    int getX() {
    2.11 +    int getXInternal() {
    2.12          return x;
    2.13      }
    2.14  
    2.15      /** Returns the y-coordinate of the player.
    2.16 -     * @return  number from 0 to 8
    2.17 +     * @return  number from 0 to 16
    2.18       */
    2.19 -    int getY() {
    2.20 +    int getYInternal() {
    2.21          return y;
    2.22      }
    2.23  
    2.24 -    /** @return number of fences this player still has
    2.25 +    /** How much fences is still available for the player.
    2.26 +     * 
    2.27 +     * @return number of fences this player still has
    2.28       */
    2.29 -    int getFences() {
    2.30 +    public int getFences() {
    2.31          return f;
    2.32      }
    2.33  
    2.34 @@ -99,7 +101,7 @@
    2.35          }
    2.36  
    2.37          final boolean reached(Player p) {
    2.38 -            return p.getY() == finalLine;
    2.39 +            return p.getYInternal() == finalLine;
    2.40          }
    2.41      }
    2.42  }
     3.1 --- a/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java	Mon May 25 09:07:15 2009 +0200
     3.2 +++ b/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java	Thu May 28 23:26:50 2009 +0200
     3.3 @@ -26,7 +26,6 @@
     3.4  package cz.xelfi.quoridor;
     3.5  
     3.6  import cz.xelfi.quoridor.Fence.Orientation;
     3.7 -import java.util.Iterator;
     3.8  import java.util.List;
     3.9  import junit.framework.TestCase;
    3.10  
    3.11 @@ -69,11 +68,11 @@
    3.12          }
    3.13          
    3.14          
    3.15 -        assertEquals (8, list.get (0).getX());
    3.16 -        assertEquals (0, list.get (0).getY());
    3.17 +        assertEquals (8, list.get (0).getXInternal());
    3.18 +        assertEquals (0, list.get (0).getYInternal());
    3.19          assertEquals (10, list.get (0).getFences ());
    3.20 -        assertEquals (8, list.get (1).getX());
    3.21 -        assertEquals (16, list.get (1).getY());
    3.22 +        assertEquals (8, list.get (1).getXInternal());
    3.23 +        assertEquals (16, list.get (1).getYInternal());
    3.24          assertEquals (10, list.get (1).getFences ());
    3.25      }
    3.26      
    3.27 @@ -205,8 +204,8 @@
    3.28          
    3.29          b = move(b, 0, Player.Direction.NORTH);
    3.30          
    3.31 -        assertEquals (8, b.getPlayers ().get (0).getX ());
    3.32 -        assertEquals (8, b.getPlayers ().get (0).getY ());
    3.33 +        assertEquals (8, b.getPlayers ().get (0).getXInternal());
    3.34 +        assertEquals (8, b.getPlayers ().get (0).getYInternal());
    3.35          
    3.36          b = fence(b, 0, 'D', 4, Fence.Orientation.HORIZONTAL);
    3.37          
    3.38 @@ -280,7 +279,6 @@
    3.39          if (p3.equals (p5)) fail ();
    3.40          if (p4.equals (p5)) fail ();
    3.41          if (p5.equals (p4)) fail ();
    3.42 -        if (p5.equals ("Ahoj")) fail ();
    3.43      }
    3.44      
    3.45      public void testEqualsOfFences () throws Exception {