From 594d0a382d1f37c2b631ff7420c345e86a0922dd Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Thu, 25 Jan 2018 11:43:44 +0100
Subject: [PATCH] Better README, add technical details

---
 README.md         |  20 +++++-
 RPS_network_2.dot |  34 ++++++++++
 RPS_network_2.svg | 169 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 222 insertions(+), 1 deletion(-)
 create mode 100644 RPS_network_2.dot
 create mode 100644 RPS_network_2.svg

diff --git a/README.md b/README.md
index 08ea578..2bf8a5f 100644
--- a/README.md
+++ b/README.md
@@ -10,4 +10,22 @@ The rules are given by Sheldon in episode 8 of season 2 of TBBT (The Big Bang Th
 
 Winning should be difficult after a few dozens of rounds, because it's hard to play at random.
 
-Setting "draw is lost" and/or increasing number of inputs can improve bot level.
+Setting "winner bot" and/or increasing memory can improve bot level.
+
+---
+
+## Technical details
+
+Each potential choice is linked to all outputs in a (neural) network, for
+each input in memory. We thus have size of memory x (number of choice)^2 links.
+To select a move, the bot computes the sum of all links weights from an activated choice
+(that is to say, the value of a memory cell) to each output.
+The output with biggest weights sum wins: the move is played.
+
+The reward is then determined from human move: -1 for a loss, 0 for a draw
+(except if "winner bot" is selected, in which case a draw = a loss) and 1 for a win.
+Weights on the active links are updated positively or negatively depending on reward sign.
+All weights are initialized to zero, and since some time is required for learning
+the first moves in the game would be quite random.
+
+See RPS\_network\_2.svg file for an illustration with memory=2 and simple RPS.
diff --git a/RPS_network_2.dot b/RPS_network_2.dot
new file mode 100644
index 0000000..b5e3b79
--- /dev/null
+++ b/RPS_network_2.dot
@@ -0,0 +1,34 @@
+digraph G {
+	rankdir=LR;
+
+	subgraph inputs {
+		input1
+		input2
+		label = "Memory";
+	}
+
+	subgraph outputs {
+		Rock
+		Paper
+		Scissors
+	}
+
+	input1 -> Rock [label="Paper"]
+	input1 -> Rock [label="Rock"]
+	input1 -> Rock [label="Scissors"]
+	input1 -> Paper [label="Rock"]
+	input1 -> Paper [label="Paper"]
+	input1 -> Paper [label="Scissors"]
+	input1 -> Scissors [label="Rock"]
+	input1 -> Scissors [label="Paper"]
+	input1 -> Scissors [label="Scissors"]
+	input2 -> Rock [label="Paper"]
+	input2 -> Rock [label="Rock"]
+	input2 -> Rock [label="Scissors"]
+	input2 -> Paper [label="Rock"]
+	input2 -> Paper [label="Paper"]
+	input2 -> Paper [label="Scissors"]
+	input2 -> Scissors [label="Rock"]
+	input2 -> Scissors [label="Paper"]
+	input2 -> Scissors [label="Scissors"]
+}
diff --git a/RPS_network_2.svg b/RPS_network_2.svg
new file mode 100644
index 0000000..4454769
--- /dev/null
+++ b/RPS_network_2.svg
@@ -0,0 +1,169 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Generated by graphviz version 2.40.1 (20161225.0304)
+ -->
+<!-- Title: G Pages: 1 -->
+<svg width="287pt" height="649pt"
+ viewBox="0.00 0.00 286.98 648.62" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 644.6156)">
+<title>G</title>
+<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-644.6156 282.9839,-644.6156 282.9839,4 -4,4"/>
+<!-- input1 -->
+<g id="node1" class="node">
+<title>input1</title>
+<ellipse fill="none" stroke="#000000" cx="40.9464" cy="-371.6156" rx="40.8928" ry="18"/>
+<text text-anchor="middle" x="40.9464" y="-367.9156" font-family="Times,serif" font-size="14.00" fill="#000000">input1</text>
+</g>
+<!-- Rock -->
+<g id="node3" class="node">
+<title>Rock</title>
+<ellipse fill="none" stroke="#000000" cx="228.9383" cy="-295.6156" rx="34.394" ry="18"/>
+<text text-anchor="middle" x="228.9383" y="-291.9156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input1&#45;&gt;Rock -->
+<g id="edge1" class="edge">
+<title>input1&#45;&gt;Rock</title>
+<path fill="none" stroke="#000000" d="M43.068,-389.8583C47.5881,-419.333 61.1504,-476.6436 99.8927,-501.6156 122.6803,-516.3037 138.9206,-517.4976 160.8927,-501.6156 190.1745,-480.4501 213.7844,-375.3104 223.7778,-323.9491"/>
+<polygon fill="#000000" stroke="#000000" points="227.2675,-324.3333 225.7008,-313.855 220.3912,-323.0233 227.2675,-324.3333"/>
+<text text-anchor="middle" x="130.3927" y="-516.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input1&#45;&gt;Rock -->
+<g id="edge2" class="edge">
+<title>input1&#45;&gt;Rock</title>
+<path fill="none" stroke="#000000" d="M81.5776,-369.1101C105.5264,-366.4447 135.9274,-360.9479 160.8927,-349.6156 177.34,-342.1499 193.2911,-329.8507 205.6105,-318.8746"/>
+<polygon fill="#000000" stroke="#000000" points="208.1749,-321.2707 213.1504,-311.9168 203.4277,-316.1263 208.1749,-321.2707"/>
+<text text-anchor="middle" x="130.3927" y="-369.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input1&#45;&gt;Rock -->
+<g id="edge3" class="edge">
+<title>input1&#45;&gt;Rock</title>
+<path fill="none" stroke="#000000" d="M60.3613,-355.5678C71.3852,-347.1299 85.7701,-337.2004 99.8927,-330.6156 115.4122,-323.3795 155.903,-312.8595 187.4286,-305.2438"/>
+<polygon fill="#000000" stroke="#000000" points="188.3948,-308.6115 197.3062,-302.8811 186.7663,-301.8036 188.3948,-308.6115"/>
+<text text-anchor="middle" x="130.3927" y="-334.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+<!-- Paper -->
+<g id="node4" class="node">
+<title>Paper</title>
+<ellipse fill="none" stroke="#000000" cx="228.9383" cy="-523.6156" rx="37.8943" ry="18"/>
+<text text-anchor="middle" x="228.9383" y="-519.9156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input1&#45;&gt;Paper -->
+<g id="edge4" class="edge">
+<title>input1&#45;&gt;Paper</title>
+<path fill="none" stroke="#000000" d="M42.4894,-389.6774C47.3056,-441.2534 63.9375,-587.3122 99.8927,-615.6156 121.1955,-632.3848 136.6844,-627.8209 160.8927,-615.6156 187.6256,-602.1375 206.4647,-572.6468 217.44,-550.6664"/>
+<polygon fill="#000000" stroke="#000000" points="220.6748,-552.0132 221.7959,-541.4778 214.3496,-549.0146 220.6748,-552.0132"/>
+<text text-anchor="middle" x="130.3927" y="-629.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input1&#45;&gt;Paper -->
+<g id="edge5" class="edge">
+<title>input1&#45;&gt;Paper</title>
+<path fill="none" stroke="#000000" d="M43.36,-389.8153C49.8679,-435.7942 69.3734,-554.6045 99.8927,-577.6156 132.5444,-602.2345 178.0703,-571.1074 205.4096,-546.9155"/>
+<polygon fill="#000000" stroke="#000000" points="207.9339,-549.3497 212.9442,-540.0144 203.2059,-544.1877 207.9339,-549.3497"/>
+<text text-anchor="middle" x="130.3927" y="-589.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input1&#45;&gt;Paper -->
+<g id="edge6" class="edge">
+<title>input1&#45;&gt;Paper</title>
+<path fill="none" stroke="#000000" d="M44.8843,-389.6619C53.626,-427.8696 75.7923,-514.8106 99.8927,-531.6156 125.8846,-549.7395 162.4499,-545.443 190.0245,-537.9415"/>
+<polygon fill="#000000" stroke="#000000" points="191.1436,-541.2605 199.7406,-535.0684 189.1585,-534.5478 191.1436,-541.2605"/>
+<text text-anchor="middle" x="130.3927" y="-547.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+<!-- Scissors -->
+<g id="node5" class="node">
+<title>Scissors</title>
+<ellipse fill="none" stroke="#000000" cx="228.9383" cy="-86.6156" rx="50.0912" ry="18"/>
+<text text-anchor="middle" x="228.9383" y="-82.9156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+<!-- input1&#45;&gt;Scissors -->
+<g id="edge7" class="edge">
+<title>input1&#45;&gt;Scissors</title>
+<path fill="none" stroke="#000000" d="M49.7995,-353.9611C59.6693,-336.0116 77.2636,-308.6296 99.8927,-292.6156 123.0716,-276.2126 140.3473,-293.2168 160.8927,-273.6156 205.982,-230.5988 221.3135,-155.3608 226.4368,-114.6654"/>
+<polygon fill="#000000" stroke="#000000" points="229.9255,-114.9627 227.5797,-104.6308 222.9704,-114.1705 229.9255,-114.9627"/>
+<text text-anchor="middle" x="130.3927" y="-296.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input1&#45;&gt;Scissors -->
+<g id="edge8" class="edge">
+<title>input1&#45;&gt;Scissors</title>
+<path fill="none" stroke="#000000" d="M47.5201,-353.5795C56.1637,-329.4423 71.4714,-285.1959 81.8927,-246.6156 91.8493,-209.7558 77.5588,-193.5829 99.8927,-162.6156 106.0183,-154.1222 155.5402,-126.2204 191.4131,-106.7016"/>
+<polygon fill="#000000" stroke="#000000" points="193.5377,-109.5312 200.6623,-101.6896 190.2027,-103.3767 193.5377,-109.5312"/>
+<text text-anchor="middle" x="130.3927" y="-166.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input1&#45;&gt;Scissors -->
+<g id="edge9" class="edge">
+<title>input1&#45;&gt;Scissors</title>
+<path fill="none" stroke="#000000" d="M48.0153,-353.7021C57.207,-329.7004 73.1201,-285.6039 81.8927,-246.6156 88.8752,-215.5834 77.5421,-127.2475 99.8927,-104.6156 109.6679,-94.7174 139.8392,-90.1754 168.5509,-88.1277"/>
+<polygon fill="#000000" stroke="#000000" points="168.8462,-91.6162 178.6099,-87.5027 168.4121,-84.6297 168.8462,-91.6162"/>
+<text text-anchor="middle" x="130.3927" y="-108.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+<!-- input2 -->
+<g id="node2" class="node">
+<title>input2</title>
+<ellipse fill="none" stroke="#000000" cx="40.9464" cy="-219.6156" rx="40.8928" ry="18"/>
+<text text-anchor="middle" x="40.9464" y="-215.9156" font-family="Times,serif" font-size="14.00" fill="#000000">input2</text>
+</g>
+<!-- input2&#45;&gt;Rock -->
+<g id="edge10" class="edge">
+<title>input2&#45;&gt;Rock</title>
+<path fill="none" stroke="#000000" d="M75.9492,-229.1483C100.2103,-236.2004 133.033,-246.6326 160.8927,-258.6156 173.0525,-263.8458 185.9219,-270.5244 197.1572,-276.7643"/>
+<polygon fill="#000000" stroke="#000000" points="195.7327,-279.9798 206.1592,-281.8611 199.1817,-273.8884 195.7327,-279.9798"/>
+<text text-anchor="middle" x="130.3927" y="-262.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input2&#45;&gt;Rock -->
+<g id="edge11" class="edge">
+<title>input2&#45;&gt;Rock</title>
+<path fill="none" stroke="#000000" d="M77.2292,-211.1503C101.918,-207.2304 134.7289,-205.7199 160.8927,-217.6156 184.2297,-228.2261 202.6877,-251.2324 214.4575,-269.5245"/>
+<polygon fill="#000000" stroke="#000000" points="211.4764,-271.3585 219.6902,-278.0506 217.4424,-267.697 211.4764,-271.3585"/>
+<text text-anchor="middle" x="130.3927" y="-221.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input2&#45;&gt;Rock -->
+<g id="edge12" class="edge">
+<title>input2&#45;&gt;Rock</title>
+<path fill="none" stroke="#000000" d="M63.3933,-204.4429C88.4541,-189.5665 129.5972,-171.4299 160.8927,-188.6156 191.3857,-205.3606 210.161,-242.2035 220.0659,-267.9519"/>
+<polygon fill="#000000" stroke="#000000" points="216.8463,-269.3403 223.548,-277.5462 223.4263,-266.9521 216.8463,-269.3403"/>
+<text text-anchor="middle" x="130.3927" y="-192.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+<!-- input2&#45;&gt;Paper -->
+<g id="edge13" class="edge">
+<title>input2&#45;&gt;Paper</title>
+<path fill="none" stroke="#000000" d="M47.8748,-237.5617C56.9109,-261.5993 72.6522,-305.7356 81.8927,-344.6156 94.2612,-396.6565 65.0468,-423.0325 99.8927,-463.6156 118.391,-485.1595 134.9894,-470.9821 160.8927,-482.6156 173.6994,-488.3673 187.0796,-496.027 198.5526,-503.1682"/>
+<polygon fill="#000000" stroke="#000000" points="196.9826,-506.3178 207.2974,-508.7377 200.743,-500.4136 196.9826,-506.3178"/>
+<text text-anchor="middle" x="130.3927" y="-486.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input2&#45;&gt;Paper -->
+<g id="edge14" class="edge">
+<title>input2&#45;&gt;Paper</title>
+<path fill="none" stroke="#000000" d="M47.4763,-237.6636C56.0713,-261.8141 71.3253,-306.075 81.8927,-344.6156 91.6444,-380.1811 74.9241,-398.4759 99.8927,-425.6156 119.1183,-446.5129 137.154,-429.0338 160.8927,-444.6156 181.8978,-458.4031 200.1292,-480.4643 212.4196,-497.7737"/>
+<polygon fill="#000000" stroke="#000000" points="209.7434,-500.0595 218.2883,-506.3233 215.5145,-496.098 209.7434,-500.0595"/>
+<text text-anchor="middle" x="130.3927" y="-448.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input2&#45;&gt;Paper -->
+<g id="edge15" class="edge">
+<title>input2&#45;&gt;Paper</title>
+<path fill="none" stroke="#000000" d="M46.8814,-237.508C60.7374,-279.0951 94.4564,-379.1628 99.8927,-384.6156 120.2411,-405.0254 138.7586,-388.1576 160.8927,-406.6156 189.5366,-430.5022 208.8191,-469.7452 219.3374,-496.1201"/>
+<polygon fill="#000000" stroke="#000000" points="216.0988,-497.4502 222.9408,-505.5396 222.6368,-494.9491 216.0988,-497.4502"/>
+<text text-anchor="middle" x="130.3927" y="-410.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+<!-- input2&#45;&gt;Scissors -->
+<g id="edge16" class="edge">
+<title>input2&#45;&gt;Scissors</title>
+<path fill="none" stroke="#000000" d="M45.319,-201.4639C54.5501,-164.8311 77.0618,-84.2119 99.8927,-68.6156 126.2921,-50.5816 162.8756,-57.9471 190.3514,-68.1631"/>
+<polygon fill="#000000" stroke="#000000" points="189.0727,-71.4211 199.6585,-71.8586 191.6559,-64.9152 189.0727,-71.4211"/>
+<text text-anchor="middle" x="130.3927" y="-72.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Rock</text>
+</g>
+<!-- input2&#45;&gt;Scissors -->
+<g id="edge17" class="edge">
+<title>input2&#45;&gt;Scissors</title>
+<path fill="none" stroke="#000000" d="M44.1028,-201.4703C51.7965,-159.5828 72.8823,-58.2258 99.8927,-38.6156 131.446,-15.7072 175.1841,-41.4831 202.7668,-63.201"/>
+<polygon fill="#000000" stroke="#000000" points="200.8203,-66.1306 210.7769,-69.7524 205.2521,-60.7121 200.8203,-66.1306"/>
+<text text-anchor="middle" x="130.3927" y="-42.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Paper</text>
+</g>
+<!-- input2&#45;&gt;Scissors -->
+<g id="edge18" class="edge">
+<title>input2&#45;&gt;Scissors</title>
+<path fill="none" stroke="#000000" d="M43.2707,-201.4939C49.6295,-155.1027 68.9316,-34.0523 99.8927,-10.6156 121.5091,5.7473 136.141,.4462 160.8927,-10.6156 183.4737,-20.7073 201.6681,-42.4063 213.5417,-60.045"/>
+<polygon fill="#000000" stroke="#000000" points="210.821,-62.2861 219.1645,-68.8158 216.714,-58.5082 210.821,-62.2861"/>
+<text text-anchor="middle" x="130.3927" y="-14.4156" font-family="Times,serif" font-size="14.00" fill="#000000">Scissors</text>
+</g>
+</g>
+</svg>
-- 
2.44.0