-
Notifications
You must be signed in to change notification settings - Fork 0
/
StandardMoveLogic.h
63 lines (54 loc) · 2.34 KB
/
StandardMoveLogic.h
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
/*
* Roni Fultheim, ID: 313465965
* StandardMoveLogic.h
*/
#ifndef STANDARDMOVELOGIC_H_
#define STANDARDMOVELOGIC_H_
#include "MoveLogic.h"
/**
* Represent the standard move logic of a Reversi game.
* A move is allowed only if it changes square colors, and square colors are changed if the new
* move blocks a range of squares with the opposite color between move and a same-colored square.
*/
class StandardMoveLogic: public MoveLogic {
public:
/**
* Plays the given move for the given player on given board, according to the logic decided.
* Changes must be made to board, so it cannot be constant.
* Derived from parent class, originally a pure virtual method.
*
* Plays a move by switching the color of all consequent same-colored squares from given move.
*
* @param move location of chosen move
* @param player pointer to player playing move
* @param board pointer to board on which move is played
*/
virtual void playMove(const Location& move, const Player* player, Board* board) const;
/**
* Returns if a given move by a given player on given board is allowed.
* Derived from parent class, originally a pure virtual method.
*
* A move is allowed if it causes at least one other square to change color.
*
* @param move location of move to check if legal
* @param player pointer to player playing this move
* @param board pointer to board on which move is played
* @return true if move is legal and can be played
*/
virtual bool isMoveAllowed(const Location& move, const Player* player, const Board* board) const;
protected:
/**
* Checks if given move is an option for given player to make on the given board,
* and if so - saves location of last square in opposite-colored range to the passed Locations array.
*
* In the standard rules, a direction can be possible for a move if it has at least one neightboring
* square with opposite color, and if opposite colored square range is flanked by a square with same
* color as move's.
*
* @param dirs array of 8 locations, initialized to checked move option location
* @param player pointer to player making the move
* @param board pointer to board on which move is to be played
*/
virtual void possibleMoveDirections(Location* dirs, const Player* player, const Board* board) const;
};
#endif /* STANDARDMOVELOGIC_H_ */