diff --git a/requirements.txt b/requirements.txt
index 412786c..fde311d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,4 @@
Flask~=2.2
Flask-SocketIO~=5.3
+# Prevent polling sockets.
+simple-websocket~=0.9
diff --git a/risk.pdf b/risk.pdf
new file mode 100644
index 0000000..9c51d81
Binary files /dev/null and b/risk.pdf differ
diff --git a/static/js/index.js b/static/js/index.js
index 00e76ab..fe70626 100644
--- a/static/js/index.js
+++ b/static/js/index.js
@@ -76,20 +76,22 @@ document.addEventListener("DOMContentLoaded", () => {
barrier.resolve(data);
break;
- case "CLAIM":
+ case "ACT":
if (data.author !== currentPlayer().id) {
return;
}
- // Claim a region in the pregame.
- if (currentPlayer().claim(data)) {
- // Increment to next player.
+ if (!allRegionsClaimed()) {
+ // Claim a region in the pregame.
+ if (currentPlayer().claim(data)) {
+ // Increment to next player.
+ currentPlayer().endTurn();
+ }
+ } else if (!allReinforcementsPlaced()) {
+ currentPlayer().reinforce(data);
currentPlayer().endTurn();
}
- if (allRegionsClaimed()) {
- console.log("switching to initial reinforcements");
- }
updateDom();
break;
}
diff --git a/static/js/map.js b/static/js/map.js
index 4174dc9..c70836f 100644
--- a/static/js/map.js
+++ b/static/js/map.js
@@ -27,15 +27,6 @@ class Region {
return REGIONS[name];
}
- /**
- * Test if all regions are claimed or not.
- *
- * @returns {boolean}
- */
- static allClaimed() {
- return Object.values(REGIONS).find((r) => r.owner === null) === null;
- }
-
claim(player) {
this.owner = player;
this.strength = 1;
@@ -64,3 +55,20 @@ const E = new Region("E", WEST);
function allRegionsClaimed() {
return Object.values(REGIONS).find((region) => region.owner === null) === undefined;
}
+
+let allPlaced = false;
+
+function allReinforcementsPlaced() {
+ if (allPlaced) {
+ return true;
+ } else {
+ let totalStrength = Object.values(REGIONS).reduce(
+ (counter, region) => counter + region.strength,
+ 0
+ );
+ let numPlayers = Object.values(players).length;
+
+ allPlaced = totalStrength >= numPlayers * 5 * (10 - numPlayers);
+ return allPlaced;
+ }
+}
diff --git a/static/js/packet.js b/static/js/packet.js
index 7d9dd50..69455b0 100644
--- a/static/js/packet.js
+++ b/static/js/packet.js
@@ -35,7 +35,14 @@ class Packet {
static createRegionClaim(region) {
return {
- ...this._createBase("CLAIM"),
+ ...this._createBase("ACT"),
+ region: region,
+ };
+ }
+
+ static createReinforce(region) {
+ return {
+ ...this._createBase("ACT"),
region: region,
};
}
diff --git a/static/js/player.js b/static/js/player.js
index 5aca1d3..0978735 100644
--- a/static/js/player.js
+++ b/static/js/player.js
@@ -46,6 +46,22 @@ class Player {
}
}
+ /**
+ * Reinforce a region of the map.
+ *
+ * @param data Data received via socket.
+ */
+ reinforce(data) {
+ let region = Region.getRegion(data.region);
+
+ if (region.owner === this) {
+ region.reinforce(1);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* Start a player's turn.
*/
diff --git a/whitepaper/demonstration/Risk_game_board.png b/whitepaper/demonstration/Risk_game_board.png
new file mode 100644
index 0000000..020a9a5
Binary files /dev/null and b/whitepaper/demonstration/Risk_game_board.png differ
diff --git a/whitepaper/demonstration/Risk_game_board.svg b/whitepaper/demonstration/Risk_game_board.svg
new file mode 100644
index 0000000..fa94ed6
--- /dev/null
+++ b/whitepaper/demonstration/Risk_game_board.svg
@@ -0,0 +1,170 @@
+
+
+
\ No newline at end of file
diff --git a/whitepaper/demonstration/Risk_game_graph.svg b/whitepaper/demonstration/Risk_game_graph.svg
new file mode 100644
index 0000000..57591be
--- /dev/null
+++ b/whitepaper/demonstration/Risk_game_graph.svg
@@ -0,0 +1,91 @@
+
+
+
diff --git a/whitepaper/demonstration/fog-of-war.png b/whitepaper/demonstration/fog-of-war.png
new file mode 100644
index 0000000..cb853ee
Binary files /dev/null and b/whitepaper/demonstration/fog-of-war.png differ
diff --git a/whitepaper/demonstration/fog-of-war.webp b/whitepaper/demonstration/fog-of-war.webp
new file mode 100644
index 0000000..0e55b37
Binary files /dev/null and b/whitepaper/demonstration/fog-of-war.webp differ
diff --git a/whitepaper/demonstration/presentation.pdf b/whitepaper/demonstration/presentation.pdf
index e5f7c63..aab8850 100644
Binary files a/whitepaper/demonstration/presentation.pdf and b/whitepaper/demonstration/presentation.pdf differ
diff --git a/whitepaper/demonstration/presentation.tex b/whitepaper/demonstration/presentation.tex
index 9d60e96..d09dfa6 100644
--- a/whitepaper/demonstration/presentation.tex
+++ b/whitepaper/demonstration/presentation.tex
@@ -1,6 +1,8 @@
\documentclass{beamer}
\usetheme{default}
+\graphicspath{.}
+
\setbeamertemplate{frametitle}[default][center]
\title{"Risk" in an untrusted setting}
@@ -16,13 +18,19 @@
\item A player owns a region of the map by stationing troops within the region.
\item Players fight for regions by gambling some of their troops against the troops in the other player's region.
\end{itemize}
+\begin{center}
+ \includegraphics[width=6cm]{Risk_game_board}
+\end{center}
\end{frame}
\begin{frame}{Risk}
\begin{itemize}
\item \textit{Risk} has a variant called "fog of war".
- \item In this variant, players cannot see the number of troops stationed within regions they don't control, or don't neighbour.
+ \item In this variant, players can only see the number of troops stationed within regions they neighbour.
\item This variant is therefore only played online, in a \textbf{trusted setup}.
\end{itemize}
+\begin{center}
+ \includegraphics[width=6cm]{fog-of-war}
+\end{center}
\end{frame}
\begin{frame}{Proposition}
\begin{itemize}
@@ -35,6 +43,7 @@
\item \textbf{Federation} \begin{itemize}
\item Federated platforms can have longer lifespans than centralised platforms.
\item Federated platforms are more resistant to censorship and can help promote anonymity and privacy.
+ \item Federated platforms encourage user freedom.
\end{itemize}
\item \textbf{Security} \begin{itemize}
\item Constantly looking for ways to secure against threats specific to federated and decentralised infrastructures.
@@ -66,4 +75,7 @@
\begin{frame}{Results}
Implementation of Risk.
\end{frame}
+\begin{frame}{Citations}
+ \textit{Image} Risk game board by CMG Lee, the asterisk denoting the missing link in the 40th Anniversary Collector's Edition, based on shapes from http://commons.wikimedia.org/wiki/File:Risk\_board.svg. 11 November 2008. CC-BY-SA 4.0
+\end{frame}
\end{document}