Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: chellmuth/hive-viewer
base: be62315da0
...
head fork: chellmuth/hive-viewer
compare: c3210e961b
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
20 lib/move_finder.dart
@@ -27,6 +27,26 @@ bool _checkSlideRulesOnTransition(List<Coordinate> transition, GameState gamesta
return true;
}
+class AtopHiveMoveFinder {
+ static List<Move> findMoves(Piece piece, GameState gamestate) {
+ List<Move> moves = [];
+
+ var height = gamestate.getHeight(piece);
+ if (height == 1) { return []; }
+
+ var locations = new Set<Coordinate>();
+ Coordinate location = gamestate.locate(piece);
+ for (Tile neighbor in gamestate.neighbors(location)) {
+ locations.add(neighbor.coordinate);
+ }
+
+ for (Coordinate targetLocation in locations) {
+ moves.add(new Move(piece, location, targetLocation));
+ }
+ return moves;
+ }
+}
+
class DismountHiveMoveFinder {
static List<Move> findMoves(Piece piece, GameState gamestate) {
List<Move> moves = [];
View
1  lib/piece_impl.dart
@@ -20,6 +20,7 @@ class Beetle extends Piece {
moves.addAll(ClimbHiveMoveFinder.findMoves(this, gamestate));
} else {
moves.addAll(DismountHiveMoveFinder.findMoves(this, gamestate));
+ moves.addAll(AtopHiveMoveFinder.findMoves(this, gamestate));
}
return moves;
}
View
64 test/move_finder_test.dart
@@ -7,6 +7,7 @@ class TestMoveFinder {
group('Ranged Slide Finder:', _rangedSlideFinder);
group('Climb Hive Finder:', _climbHiveFinder);
group('Dismount Hive Finder:', _dismountHiveFinder);
+ group('Atop Hive Finder:', _atopHiveFinder);
});
}
@@ -291,4 +292,67 @@ class TestMoveFinder {
expect(moves.map((move) => move.targetLocation).toList(), equals(moveCoordinates));
});
}
+
+ static void _atopHiveFinder() {
+ test('move on top of adjacent pieces', () {
+ var _wB_ = new Piece(Player.WHITE, Bug.BEETLE, 1);
+ var gamestate = GameStateTestHelper.build([
+ [ 'wG', ' ', 'wG' ],
+ [ 'wG', ' ', ' ' ],
+ [ _wB_, 'wG', ' ' ]
+ ]);
+ gamestate.stepToEnd();
+
+ Piece piece = _wB_;
+ gamestate.appendMove(new Move(piece, new Coordinate(2, 0), new Coordinate(1, 0)));
+ gamestate.stepToEnd();
+
+ var moves = AtopHiveMoveFinder.findMoves(piece, gamestate);
+ var moveCoordinates = [
+ new Coordinate(0, 0),
+ new Coordinate(2, 1)
+ ];
+ expect(moves.map((move) => move.targetLocation).toList(), equals(moveCoordinates));
+ });
+
+ test('empty when not atop the hive', () {
+ var _wB_ = new Piece(Player.WHITE, Bug.BEETLE, 1);
+ var gamestate = GameStateTestHelper.build([
+ [ 'wG', ' ', 'wG' ],
+ [ 'wG', ' ', ' ' ],
+ [ _wB_, 'wG', ' ' ]
+ ]);
+ gamestate.stepToEnd();
+
+ Piece piece = _wB_;
+
+ var moves = AtopHiveMoveFinder.findMoves(piece, gamestate);
+ expect(moves.isEmpty, isTrue);
+ });
+
+ test('elevation is no obstacle', () {
+ var _wB_ = new Piece(Player.WHITE, Bug.BEETLE, 1);
+ var _bB_ = new Piece(Player.BLACK, Bug.BEETLE, 1);
+ var gamestate = GameStateTestHelper.build([
+ [ 'wG', _bB_, 'wG' ],
+ [ 'wG', ' ', ' ' ],
+ [ _wB_, 'wG', ' ' ]
+ ]);
+ gamestate.stepToEnd();
+
+ Piece piece = _wB_;
+ Piece otherBeetle = _bB_;
+ gamestate.appendMove(new Move(piece, new Coordinate(2, 0), new Coordinate(1, 0)));
+ gamestate.stepToEnd();
+ gamestate.appendMove(new Move(otherBeetle, new Coordinate(0, 1), new Coordinate(0, 0)));
+ gamestate.stepToEnd();
+
+ var moves = AtopHiveMoveFinder.findMoves(piece, gamestate);
+ var moveCoordinates = [
+ new Coordinate(0, 0),
+ new Coordinate(2, 1)
+ ];
+ expect(moves.map((move) => move.targetLocation).toList(), equals(moveCoordinates));
+ });
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.