Skip to content

Method: OthelloPlayerImpl(OthelloPlayer)

1: /*
2: * Copyright © 2020 Fachhochschule für die Wirtschaft (FHDW) Hannover
3: *
4: * This file is part of othello-core.
5: *
6: * Othello-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: * Othello-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: * othello-core. If not, see <http://www.gnu.org/licenses/>.
18: */
19: package de.fhdw.gaming.othello.core.domain.impl;
20:
21: import de.fhdw.gaming.core.domain.AbstractPlayer;
22: import de.fhdw.gaming.othello.core.domain.OthelloFieldState;
23: import de.fhdw.gaming.othello.core.domain.OthelloPlayer;
24:
25: /**
26: * Implements {@link OthelloPlayer}.
27: */
28: final class OthelloPlayerImpl extends AbstractPlayer<OthelloPlayer> implements OthelloPlayer {
29:
30: /**
31: * {@code true} if this player uses the black tokens, or {@code false} if she uses the white tokens.
32: */
33: private final boolean usingBlackTokens;
34:
35: /**
36: * Creates an Othello player.
37: *
38: * @param name The name of the player.
39: * @param usingBlackTokens {@code true} if this player uses the black tokens, or {@code false} if she uses the white
40: * tokens.
41: */
42: OthelloPlayerImpl(final String name, final boolean usingBlackTokens) {
43: super(name);
44: this.usingBlackTokens = usingBlackTokens;
45: }
46:
47: /**
48: * Creates an Othello player.
49: *
50: * @param source The {@link OthelloPlayer} to copy.
51: */
52: OthelloPlayerImpl(final OthelloPlayer source) {
53: super(source);
54: this.usingBlackTokens = source.isUsingBlackTokens();
55: }
56:
57: @Override
58: public String toString() {
59: return String.format(
60: "OthelloPlayer[name=%s, tokens=%s, state=%s, outcome=%s]",
61: this.getName(),
62: this.usingBlackTokens ? OthelloFieldState.BLACK.toString() : OthelloFieldState.WHITE.toString(),
63: this.getState(),
64: this.getOutcome());
65: }
66:
67: @Override
68: public boolean equals(final Object obj) {
69: if (obj instanceof OthelloPlayerImpl) {
70: final OthelloPlayerImpl other = (OthelloPlayerImpl) obj;
71: return super.equals(obj) && this.usingBlackTokens == other.usingBlackTokens;
72: }
73: return false;
74: }
75:
76: @Override
77: public int hashCode() {
78: return super.hashCode() ^ Boolean.hashCode(this.usingBlackTokens);
79: }
80:
81: @Override
82: public boolean isUsingBlackTokens() {
83: return this.usingBlackTokens;
84: }
85:
86: @Override
87: public OthelloPlayer deepCopy() {
88: return new OthelloPlayerImpl(this);
89: }
90: }