Skip to content

Package: TicTacToeDirection$4

TicTacToeDirection$4

nameinstructionbranchcomplexitylinemethod
step(TicTacToePosition)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
{...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * Copyright © 2021-2023 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of ipspiel24-tictactoe-core.
5: *
6: * ipspiel24-tictactoe-core is free software: you can redistribute it and/or modify it under
7: * the terms of the GNU General Public License as published by the Free Software
8: * Foundation, either version 3 of the License, or (at your option) any later
9: * version.
10: *
11: * ipspiel24-tictactoe-core is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14: * details.
15: *
16: * You should have received a copy of the GNU General Public License along with
17: * ipspiel24-tictactoe-core. If not, see <http://www.gnu.org/licenses/>.
18: */
19: package de.fhdw.gaming.ipspiel24.tictactoe.core.domain;
20:
21: /**
22: * Represents a direction on the Tic Tac Toe board.
23: */
24: public enum TicTacToeDirection {
25:
26: /**
27: * Upwards.
28: */
29: NORTH {
30: @Override
31: public TicTacToePosition step(final TicTacToePosition origin) {
32: return origin.offset(-1, 0);
33: }
34: },
35:
36: /**
37: * Upwards and to the right.
38: */
39: NORTHEAST {
40: @Override
41: public TicTacToePosition step(final TicTacToePosition origin) {
42: return origin.offset(-1, 1);
43: }
44: },
45:
46: /**
47: * To the right.
48: */
49: EAST {
50: @Override
51: public TicTacToePosition step(final TicTacToePosition origin) {
52: return origin.offset(0, 1);
53: }
54: },
55:
56: /**
57: * Downwards and to the right.
58: */
59: SOUTHEAST {
60: @Override
61: public TicTacToePosition step(final TicTacToePosition origin) {
62: return origin.offset(1, 1);
63: }
64: },
65:
66: /**
67: * Downwards.
68: */
69: SOUTH {
70: @Override
71: public TicTacToePosition step(final TicTacToePosition origin) {
72: return origin.offset(1, 0);
73: }
74: },
75:
76: /**
77: * Downwards and to the left.
78: */
79: SOUTHWEST {
80: @Override
81: public TicTacToePosition step(final TicTacToePosition origin) {
82: return origin.offset(1, -1);
83: }
84: },
85:
86: /**
87: * To the left.
88: */
89: WEST {
90: @Override
91: public TicTacToePosition step(final TicTacToePosition origin) {
92: return origin.offset(0, -1);
93: }
94: },
95:
96: /**
97: * Upwards and to the left.
98: */
99: NORTHWEST {
100: @Override
101: public TicTacToePosition step(final TicTacToePosition origin) {
102: return origin.offset(-1, -1);
103: }
104: };
105:
106: /**
107: * Performs a step into this direction given an origin. Note that the resulting position is not checked against any
108: * bounds, so this has to be done by the caller if necessary.
109: *
110: * @param origin The origin.
111: * @return The resulting position.
112: */
113: public abstract TicTacToePosition step(TicTacToePosition origin);
114: }