summaryrefslogtreecommitdiffstats
path: root/core/test/ch/asynk/tankontank/Helpers.java
blob: 29e2969d42f00b95fdb26b4a3b7487b2aca9bd9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package ch.asynk.tankontank;

import ch.asynk.tankontank.engine.Pawn;
import ch.asynk.tankontank.engine.Tile;
import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.SearchBoard;

public class Helpers
{
    public static class FakePawn extends Pawn
    {
        private int mvt;
        public FakePawn (int mvt)
        {
            this.mvt = mvt;
        }

        public int getMovementPoints()              { return mvt; }
        public int getRoadMarchBonus()              { return 1; }
        public boolean isUnit()                     { return true; }
        public boolean isEnemy(Pawn other)          { return true; }
        public int getAngleOfAttack()               { return 0; }
        public int getAttackRangeFrom(Tile tile)    { return 3; }
    }

    public static class FakeTile extends Tile
    {
        public boolean offMap;

        public FakeTile()
        {
            super();
            offMap = false;
        }

        public FakeTile(boolean offMap)
        {
            this.offMap = offMap;
        }

        public boolean isOffMap()
        {
            return offMap;
        }
        public boolean blockLineOfSightFrom(Tile from)  { return false; }
        public boolean atLeastOneMove(Pawn pawn)        { return true; }
        public boolean road(Board.Orientation side)     { return false; }
        public boolean hasTargetsFor(Pawn pawn)         { return false; }
        public int costFrom(Pawn pawn, Board.Orientation side, boolean road) { return 1; }
    }

    public static class FakeBoard extends Board
    {
        private int cols;
        private int rows;
        public FakeTile fakeTiles[];

        public FakeBoard(int cols, int rows)
        {
            super();
            this.cols = cols;
            this.rows = rows;
            fakeTiles = new FakeTile[cols * rows];
            for (int i = 0; i < rows; i++) {
                for ( int j = 0; j < cols; j ++)
                    fakeTiles[j + (i * cols)] = new FakeTile();
            }
            fakeTiles[19].offMap = true;
            fakeTiles[39].offMap = true;
            fakeTiles[59].offMap = true;
            fakeTiles[79].offMap = true;
            this.searchBoard = new SearchBoard(this, cols, rows);
        }

        @Override
        public Tile getTile(int col, int row)
        {
            int colOffset = ((row + 1) / 2);
            if ((col < colOffset) || (row < 0) || (row >= rows) || ((col - colOffset) >= cols))
                return new FakeTile(true);
            int idx = ((col - colOffset)) + (row * cols);
            return fakeTiles[idx];
        }
    }
}