-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleEngine.java
More file actions
31 lines (25 loc) · 817 Bytes
/
RuleEngine.java
File metadata and controls
31 lines (25 loc) · 817 Bytes
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
package api;
import boards.TicTacToeBoard;
import game.Board;
import game.GameState;
import java.util.HashMap;
import java.util.Map;
public class RuleEngine {
Map<String, RuleSet> ruleMap = new HashMap<>();
public RuleEngine(){
ruleMap.put(TicTacToeBoard.class.getName(),TicTacToeBoard.getRules());
}
public GameState getState(Board board){
if(board instanceof TicTacToeBoard board1) {
for(Rule<TicTacToeBoard> rule: ruleMap.get(TicTacToeBoard.class.getName())){
GameState gameState = rule.condition.apply(board1);
if(gameState.isOver()){
return gameState;
}
}
return new GameState(false,"-");
} else {
return new GameState(true, "-");
}
}
}