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