Add some stuff

This commit is contained in:
jude 2023-02-10 15:47:21 +00:00
parent 6db33c112e
commit 235c0a0e42
13 changed files with 326 additions and 18 deletions

View File

@ -1,2 +1,4 @@
Flask~=2.2
Flask-SocketIO~=5.3
# Prevent polling sockets.
simple-websocket~=0.9

BIN
risk.pdf Normal file

Binary file not shown.

View File

@ -76,20 +76,22 @@ document.addEventListener("DOMContentLoaded", () => {
barrier.resolve(data);
break;
case "CLAIM":
case "ACT":
if (data.author !== currentPlayer().id) {
return;
}
if (!allRegionsClaimed()) {
// Claim a region in the pregame.
if (currentPlayer().claim(data)) {
// Increment to next player.
currentPlayer().endTurn();
}
if (allRegionsClaimed()) {
console.log("switching to initial reinforcements");
} else if (!allReinforcementsPlaced()) {
currentPlayer().reinforce(data);
currentPlayer().endTurn();
}
updateDom();
break;
}

View File

@ -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;
}
}

View File

@ -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,
};
}

View File

@ -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.
*/

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 117 KiB

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="-50 12 1000 750">
<title>Risk game graph</title>
<desc>The Risk game board as a graph by CMG Lee and Duomillia, the asterisk denoting the route missing in the 40th Anniversary Collector's Edition.</desc>
<style type="text/css">
.main { font-family:Helvetica,Arial,sans-serif; font-size:20px; text-anchor:middle;
fill:#000000; stroke:none; stroke-width:25px; stroke-linejoin:round; }
.huge { font-family:Bookman,Bookman Old Style,serif; font-weight:bold; font-size:90px; text-anchor:start; fill:#cccccc; }
.big { font-weight:bold; font-size:35px; letter-spacing:-1px; }
.pack { letter-spacing:-1px; }
</style>
<defs>
<filter id="filter_shadow">
<feGaussianBlur in="SourceAlpha" stdDeviation="2"/>
<feColorMatrix type="matrix" values="0,0,0,0,0 0,0,0,0,0 0,0,0,0,0 0,0,0,0.5,0"/>
<feOffset dx="0" dy="4"/>
<feBlend in="SourceGraphic"/>
</filter>
<ellipse id="node" cx="0" cy="0" rx="48" ry="43" stroke="none" filter="url(#filter_shadow)"/>
<g id="na"><use xlink:href="#node" fill="#eecc00"/></g>
<g id="sa"><use xlink:href="#node" fill="#ff9999"/></g>
<g id="eu"><use xlink:href="#node" fill="#0099ff"/></g>
<g id="af"><use xlink:href="#node" fill="#ff9900"/></g>
<g id="as"><use xlink:href="#node" fill="#00cc00"/></g>
<g id="au"><use xlink:href="#node" fill="#cc99ff"/></g>
</defs>
<circle cx="0" cy="0" r="99999" fill="#ffffff"/>
<g class="main">
<g fill="none" stroke="#cccccc">
<path d="M -10,105 q 0,-70 50,-70 h 790 q 70,0 70,70 v 100 M 200,100 l 100,100 M 0,400 v 100 M 100,500 h 300 M 400,400 v 100 l 100,-100 v 100 l 100,-100 M 600,200 l -100,100 h 100 m -100,0 l 100,100 h -100 M 800,400 v 100"/>
<path d="M 600,400 v 100 q 0,100 -100,95" stroke-dasharray="8,2"/>
<path d="M 200,200 v -100 h -200 v 300 z h -200 l 100,-100 v 200 h -100 l 200,-200" stroke="#cc9900"/>
<path d="M 0,600 h 100 v -100 z v -100 h 100" stroke="#cc6666"/>
<path d="M 400,300 l 100,100 v -100 l -100,-100 h -100 v 100 l 100,100 v -200 l -100,100 h 200 m 0,100 h -100" stroke="#0066cc"/>
<path d="M 400,700 v -200 l 100,100 z h 100 v -200 h -100 m 0,100 h 100" stroke="#cc6600"/>
<path d="M 800,100 v 200 l 100,-100 z l -100,100 v 200 l -100,-100 h 300 v -100 h -300 v 200 h 200 l -200,-200 m 100,0 l 100,100" stroke="#009900"/>
<path d="M 800,600 h 100 v -100 z v -100 h 100" stroke="#9966cc"/>
</g>
<g transform="translate( 0,100) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >1</tspan><tspan x="0" dy="3ex">Alaska</tspan></text></g>
<g transform="translate(100,100) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >6</tspan><tspan x="0" dy="2ex">Northwest</tspan><tspan x="0" dy="1em">Territory</tspan></text></g>
<g transform="translate(200,100) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >5</tspan><tspan x="0" dy="3ex" class="pack">Greenland</tspan></text></g>
<g transform="translate( 0,200) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >2</tspan><tspan x="0" dy="3ex">Alberta</tspan></text></g>
<g transform="translate(100,200) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >7</tspan><tspan x="0" dy="3ex">Ontario</tspan></text></g>
<g transform="translate(200,200) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >8</tspan><tspan x="0" dy="3ex">Quebec</tspan></text></g>
<g transform="translate( 0,300) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >9</tspan><tspan x="0" dy="2ex">Western</tspan><tspan x="0" dy="1em">US</tspan></text></g>
<g transform="translate(100,300) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >4</tspan><tspan x="0" dy="2ex">Eastern</tspan><tspan x="0" dy="1em">US</tspan></text></g>
<g transform="translate( 0,400) scale(0.9,1)"><use xlink:href="#na"/><text y="-1.5ex"><tspan class="big" >3</tspan><tspan x="0" dy="2ex">Central</tspan><tspan x="0" dy="1em">America</tspan></text></g>
<g transform="translate( 0,500) scale(0.9,1)"><use xlink:href="#sa"/><text y="-1.5ex"><tspan class="big" >4</tspan><tspan x="0" dy="3ex" class="pack">Venezuela</tspan></text></g>
<g transform="translate(100,500) scale(0.9,1)"><use xlink:href="#sa"/><text y="-1.5ex"><tspan class="big" >2</tspan><tspan x="0" dy="3ex">Brazil</tspan></text></g>
<g transform="translate( 0,600) scale(0.9,1)"><use xlink:href="#sa"/><text y="-1.5ex"><tspan class="big" >3</tspan><tspan x="0" dy="3ex">Peru</tspan></text></g>
<g transform="translate(100,600) scale(0.9,1)"><use xlink:href="#sa"/><text y="-1.5ex"><tspan class="big" >1</tspan><tspan x="0" dy="3ex">Argentina</tspan></text></g>
<g transform="translate(300,200) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >2</tspan><tspan x="0" dy="3ex">Iceland</tspan></text></g>
<g transform="translate(400,200) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >4</tspan><tspan x="0" dy="2ex">Scandi-</tspan><tspan x="0" dy="1em">navia</tspan></text></g>
<g transform="translate(300,300) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >1</tspan><tspan x="0" dy="2ex">Great</tspan><tspan x="0" dy="1em">Britain</tspan></text></g>
<g transform="translate(400,300) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >3</tspan><tspan x="0" dy="2ex">Northern</tspan><tspan x="0" dy="1em">Europe</tspan></text></g>
<g transform="translate(500,300) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >6</tspan><tspan x="0" dy="3ex">Ukraine</tspan></text></g>
<g transform="translate(400,400) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >7</tspan><tspan x="0" dy="2ex">Western</tspan><tspan x="0" dy="1em">Europe</tspan></text></g>
<g transform="translate(500,400) scale(0.9,1)"><use xlink:href="#eu"/><text y="-1.5ex"><tspan class="big" >5</tspan><tspan x="0" dy="2ex">Southern</tspan><tspan x="0" dy="1em">Europe</tspan></text></g>
<g transform="translate(400,500) scale(0.9,1)"><use xlink:href="#af"/><text y="-1.5ex"><tspan class="big" >5</tspan><tspan x="0" dy="2ex">North</tspan><tspan x="0" dy="1em">Africa</tspan></text></g>
<g transform="translate(500,500) scale(0.9,1)"><use xlink:href="#af"/><text y="-1.5ex"><tspan class="big" >3</tspan><tspan x="0" dy="3ex">Egypt</tspan></text></g>
<g transform="translate(400,600) scale(0.9,1)"><use xlink:href="#af"/><text y="-1.5ex"><tspan class="big" >1</tspan><tspan x="0" dy="3ex">Congo</tspan></text></g>
<g transform="translate(500,600) scale(0.9,1)"><use xlink:href="#af"/><text y="-1.5ex"><tspan class="big" >2</tspan><tspan x="0" dy="2ex">East</tspan><tspan x="0" dy="1em">Africa</tspan></text></g>
<g transform="translate(400,700) scale(0.9,1)"><use xlink:href="#af"/><text y="-1.5ex"><tspan class="big" >6</tspan><tspan x="0" dy="2ex">South</tspan><tspan x="0" dy="1em">Africa</tspan></text></g>
<g transform="translate(500,700) scale(0.9,1)"><use xlink:href="#af"/><text y="-1.5ex"><tspan class="big" >4</tspan><tspan x="0" dy="2ex">Mada-</tspan><tspan x="0" dy="1em">gascar</tspan></text></g>
<g transform="translate(800,100) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big">12</tspan><tspan x="0" dy="3ex">Yakutsk</tspan></text></g>
<g transform="translate(600,200) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big">11</tspan><tspan x="0" dy="3ex">Ural</tspan></text></g>
<g transform="translate(700,200) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big">10</tspan><tspan x="0" dy="3ex">Siberia</tspan></text></g>
<g transform="translate(800,200) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >4</tspan><tspan x="0" dy="3ex">Irkutsk</tspan></text></g>
<g transform="translate(900,200) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >6</tspan><tspan x="0" dy="2ex">Kam-</tspan><tspan x="0" dy="1em">chatka</tspan></text></g>
<g transform="translate(600,300) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >1</tspan><tspan x="0" dy="2ex">Afgha-</tspan><tspan x="0" dy="1em">nistan</tspan></text></g>
<g transform="translate(700,300) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >2</tspan><tspan x="0" dy="3ex">China</tspan></text></g>
<g transform="translate(800,300) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >8</tspan><tspan x="0" dy="3ex">Mongolia</tspan></text></g>
<g transform="translate(900,300) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >5</tspan><tspan x="0" dy="3ex">Japan</tspan></text></g>
<g transform="translate(600,400) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >7</tspan><tspan x="0" dy="2ex">Middle</tspan><tspan x="0" dy="1em">East</tspan></text></g>
<g transform="translate(700,400) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >3</tspan><tspan x="0" dy="3ex">India</tspan></text></g>
<g transform="translate(800,400) scale(0.9,1)"><use xlink:href="#as"/><text y="-1.5ex"><tspan class="big" >9</tspan><tspan x="0" dy="3ex">Siam</tspan></text></g>
<g transform="translate(800,500) scale(0.9,1)"><use xlink:href="#au"/><text y="-1.5ex"><tspan class="big" >2</tspan><tspan x="0" dy="3ex" class="pack">Indonesia</tspan></text></g>
<g transform="translate(900,500) scale(0.9,1)"><use xlink:href="#au"/><text y="-1.5ex"><tspan class="big" >3</tspan><tspan x="0" dy="2ex">New</tspan><tspan x="0" dy="1em">Guinea</tspan></text></g>
<g transform="translate(800,600) scale(0.9,1)"><use xlink:href="#au"/><text y="-1.5ex"><tspan class="big" >4</tspan><tspan x="0" dy="2ex">Western</tspan><tspan x="0" dy="1em">Australia</tspan></text></g>
<g transform="translate(900,600) scale(0.9,1)"><use xlink:href="#au"/><text y="-1.5ex"><tspan class="big" >1</tspan><tspan x="0" dy="2ex">Eastern</tspan><tspan x="0" dy="1em">Australia</tspan></text></g>
<g transform="translate(600,600)"><text y="0.7ex" class="huge"><tspan>*</tspan></text></g>
<g transform="translate(-42,710)"><text y="0.7ex" class="huge"><tspan>Risk</tspan></text></g>
<g transform="translate(180,360)"><text y="0.7ex" class="big"><tspan>North</tspan><tspan x="0" dy="2ex">America</tspan></text></g>
<g transform="translate(230,580)"><text y="0.7ex" class="big"><tspan>South</tspan><tspan x="0" dy="2ex">America</tspan></text></g>
<g transform="translate(400,110)"><text y="0.7ex" class="big"><tspan>Europe</tspan></text></g>
<g transform="translate(615,680)"><text y="0.7ex" class="big"><tspan>Africa</tspan></text></g>
<g transform="translate(650,100)"><text y="0.7ex" class="big"><tspan>Asia</tspan></text></g>
<g transform="translate(850,680)"><text y="0.7ex" class="big"><tspan>Australia</tspan></text></g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

View File

@ -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}