projects
/
rpsls-bot.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
977c11c
)
debug attempt with simple RPS
author
Benjamin Auder
<benjamin.auder@somewhere>
Wed, 24 Jan 2018 11:45:05 +0000
(12:45 +0100)
committer
Benjamin Auder
<benjamin.auder@somewhere>
Wed, 24 Jan 2018 11:45:05 +0000
(12:45 +0100)
rpsls.js
patch
|
blob
|
blame
|
history
diff --git
a/rpsls.js
b/rpsls.js
index
f14b617
..
661e31c
100644
(file)
--- a/
rpsls.js
+++ b/
rpsls.js
@@
-1,14
+1,14
@@
-const nChoice =
5
; //fixed for this game
+const nChoice =
3
; //fixed for this game
// Rewards matrix. Order: rock, lizard, Spock, scissors, paper
const rewards = Array.from(Array(nChoice)).map( (e,i) => { //lines
return Array.from(Array(nChoice)).map( (f,j) => { //columns
// i against j: gain from i viewpoint
// Rewards matrix. Order: rock, lizard, Spock, scissors, paper
const rewards = Array.from(Array(nChoice)).map( (e,i) => { //lines
return Array.from(Array(nChoice)).map( (f,j) => { //columns
// i against j: gain from i viewpoint
- if (j == (i+1) % nChoice || j == (i+3) % nChoice)
+ if (j == (i+1) % nChoice
)//
|| j == (i+3) % nChoice)
return 1; //I win :)
return 1; //I win :)
- else if (
(i+1) % nChoice == j || j == (i+2) % nChoice
)
+ else if (
i != j
)
return -1; //I lose :(
return -1; //I lose :(
- else
+ else
//i == j
return 0;
});
});
return 0;
});
});
@@
-64,12
+64,12
@@
new Vue({
});
// Pick a choice at random in maxValue (total random for first move)
let randIdx = Math.floor((Math.random() * candidates.length) + 1);
});
// Pick a choice at random in maxValue (total random for first move)
let randIdx = Math.floor((Math.random() * candidates.length) + 1);
- this.updateGameState(candidates[randIdx]);
+ this.updateGameState(candidates[randIdx]
.index
);
},
},
- updateGameState: function(
move
) {
- let reward = rewards[
move.val
][this.humanMove]; //viewpoint of computer
+ updateGameState: function(
index
) {
+ let reward = rewards[
index
][this.humanMove]; //viewpoint of computer
this.gameState += reward;
this.gameState += reward;
- this.updateWeights(reward,
move.
index);
+ this.updateWeights(reward, index);
},
updateWeights: function(reward, index) {
let delta = Math.sign(reward);
},
updateWeights: function(reward, index) {
let delta = Math.sign(reward);
@@
-100,7
+100,8
@@
new Vue({
});
// Update human moves history
this.humanHistory.push(this.humanMove);
});
// Update human moves history
this.humanHistory.push(this.humanMove);
- this.humanHistory.shift();
+ if (this.humanHistory.length > this.nInput)
+ this.humanHistory.shift();
},
},
});
},
},
});