Add Move class

This commit is contained in:
Anton Vakhrushev
2018-06-05 13:36:39 +03:00
parent f27fcf1210
commit 1c96ea31ad
4 changed files with 40 additions and 36 deletions

14
source/Move.js Normal file
View File

@ -0,0 +1,14 @@
export default class Move {
constructor(human, robot) {
this._human = human ? 1 : 0;
this._robot = robot ? 1 : 0;
}
get human() {
return this._human;
}
get robot() {
return this._robot;
}
}

View File

@ -1,23 +1,22 @@
import Move from './Move';
export default class Movements {
humanMovements = [];
robotMovements = [];
moves = [];
constructor(human = [], robot = []) {
this.humanMovements = human;
this.robotMovements = robot;
constructor(moves = []) {
this.moves = moves;
}
makeHumanMove(value) {
this.humanMovements.push(value === 1 ? value : 0);
}
makeRobotMove(value) {
this.robotMovements.push(value === 1 ? value : 0);
makeMove(human, robot) {
this.moves.push(new Move(human, robot));
}
getLastMovements(humanCount, robotCount) {
const humanSlice = this.humanMovements.slice(-humanCount);
const robotSlice = this.robotMovements.slice(-robotCount);
return [].concat(robotSlice, humanSlice);
const humanMoves = this.moves.map(m => m.human);
const robotMoves = this.moves.map(m => m.robot);
return [].concat(
robotMoves.slice(-robotCount),
humanMoves.slice(-humanCount)
);
}
}