[LIB-9] Add original chesshog source files
[chesshog.git] / src / main / java / org / hedgecode / chess / game / GameMoves.java
1 /*
2  * Copyright (c) 2018. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.game;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.hedgecode.chess.position.Color;
23 import org.hedgecode.chess.position.Square;
24
25 /**
26  *
27  *
28  * @author Dmitry Samoshin aka gotty
29  */
30 public class GameMoves implements Moves {
31
32     private int moveNumber;
33     private List<Move> moves;
34
35     public GameMoves() {
36         moveNumber = -1;
37         moves = new ArrayList<>();
38     }
39
40     @Override
41     public void move(Move move) {
42
43     }
44
45     @Override
46     public Move first() {
47         if (moves.isEmpty())
48             return null;
49         moveNumber = 0;
50         return moves.get(moveNumber);
51     }
52
53     @Override
54     public Move last() {
55         if (moves.isEmpty())
56             return null;
57         moveNumber = moves.size() - 1;
58         return moves.get(moveNumber);
59     }
60
61     @Override
62     public boolean hasNext() {
63         return moves.size() > moveNumber + 1;
64     }
65
66     @Override
67     public Move next() {
68         if (hasNext())
69             return moves.get(++moveNumber);
70         return null;
71     }
72
73     @Override
74     public void clear() {
75         moveNumber = -1;
76         moves.clear();
77     }
78
79     @Override
80     public int count() {
81         return moves.size();
82     }
83
84     @Override
85     public Move byNumber(int num, Color color) {
86         return null;
87     }
88
89     static class Builder {
90
91         Move build(Color color, Square from, Square to) {
92             return new GameMove(color, from, to);
93         }
94
95     }
96
97 }