diff --git a/static/js/player.js b/static/js/player.js index 431b0c4..e3b22a1 100644 --- a/static/js/player.js +++ b/static/js/player.js @@ -91,6 +91,55 @@ class Player { this.turnPhase = PHASE_ATTACK; } + return false; + } else { + // End turn prematurely. + if (data.action === "END") { + return true; + } + + if (this.turnPhase === PHASE_ATTACK && data.action === "ATTACK") { + if (this.attack(data)) { + this.turnPhase = PHASE_FORTIFY; + } + + return false; + } + + this.turnPhase = PHASE_FORTIFY; + + if (data.action === "FORTIFY") { + return this.fortify(data); + } + } + return false; + } + + /** + * Process an action which is to attack another region. + * + * @param data Data received via socket + */ + attack(data) {} + + /** + * Process an action which is to attack another region. + * + * @param data Data received via socket + */ + fortify(data) { + let sender = Region.getRegion(data.sender); + let receiver = Region.getRegion(data.receiver); + + if ( + sender.owner === this && + receiver.owner === this && + sender.strength > data.strength + ) { + receiver.reinforce(data.strength); + sender.strength -= data.strength; + return true; + } else { return false; } } diff --git a/whitepaper/Dissertation.pdf b/whitepaper/Dissertation.pdf index 71ce28c..7443681 100644 Binary files a/whitepaper/Dissertation.pdf and b/whitepaper/Dissertation.pdf differ diff --git a/whitepaper/Dissertation.tex b/whitepaper/Dissertation.tex index 4c4d337..f84fbbc 100644 --- a/whitepaper/Dissertation.tex +++ b/whitepaper/Dissertation.tex @@ -297,7 +297,7 @@ As the prime generation routine generates primes of equal length, this property We see that $(1 + n)^n \equiv 1 \mod n^2$ from binomial expansion. So $1 + n$ is invertible as required. \end{proof} -The selection of such $g$ is ideal, as the binomial expansion property helps to optimise exponentiation. Clearly, from the same result, $g^m = 1 + mn$. This operation is far easier to perform, as it can be performed without having to take the modulus to keep the computed value within range (for $m$ of sufficiently small size). +The selection of such $g$ is ideal, as the binomial expansion property helps to optimise exponentiation. Clearly, from the same result, $g^m = 1 + mn$. This operation is far easier to perform, as it can be performed without having to take the modulus to keep the computed value within range. \subsection{Encryption}