Код гадалки Шеннона перенесен в проект
This commit is contained in:
47
source/_assets/predictor/Journal.js
Normal file
47
source/_assets/predictor/Journal.js
Normal file
@ -0,0 +1,47 @@
|
||||
import Move from './Move';
|
||||
|
||||
class Journal {
|
||||
/**
|
||||
* @type {Move[]}
|
||||
*/
|
||||
moves = [];
|
||||
|
||||
/**
|
||||
* @param {Move[]} moves
|
||||
*/
|
||||
constructor(moves = []) {
|
||||
this.moves = moves;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} human
|
||||
* @param {Number} robot
|
||||
*/
|
||||
makeMove(human, robot) {
|
||||
this.moves.push(new Move(human, robot));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} humanCount
|
||||
* @param {Number} robotCount
|
||||
*
|
||||
* @returns {Number[]}
|
||||
*/
|
||||
getLastMovements(humanCount, robotCount) {
|
||||
const humanMoves = this.moves.map(m => m.human);
|
||||
const robotMoves = this.moves.map(m => m.robot);
|
||||
return [].concat(
|
||||
robotMoves.slice(-robotCount),
|
||||
humanMoves.slice(-humanCount)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Number}
|
||||
*/
|
||||
get length() {
|
||||
return this.moves.length;
|
||||
}
|
||||
}
|
||||
|
||||
export default Journal;
|
Reference in New Issue
Block a user