Skip to content

A game for better understanding nash equilibrium written by QianZehao.

License

Notifications You must be signed in to change notification settings

QianZeHao123/Nashsweeper

Repository files navigation

Nashsweeper

0x00 Introduction

Nash equilibrium is a core concept of game theory. This repo shows a playful introduction of Nash equilibrium and designs a game named Nashsweeper, which is a game designed to find the pure strategy.

0x01 How to use?

In dev mode

  • If you want to run this project, you should start the backend service firstly by changing your terminal path to nashsweeper-server and reading the readme file carefully. Then you should run the frontend service by changing your disk to nashsweeper-front and follow the readme file step by step.
  • What deserves your attention most is that both the backend and frontend services ports cannot be taken by other applications, or you won't be able to run it correctly.

In Docker Micro-service mode

This instruction only applies to Linux!!!

  • STEP 1: Make sure you have installed docker in advance. If you didn't, just run the following command:
# if you are in China, you can use tsinghua source for faster installing docker
export DOWNLOAD_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce"
# if you use curl
curl -fsSL https://get.docker.com/ | sh
# or wget
wget -O- https://get.docker.com/ | sh
  • STEP 2: Make sure you have docker-compose, git installed
sudo apt install docker-compose git
  • STEP 3: Git this repository and change disk to the repository
git clone https://gitee.com/qian_zehao/nashsweeper.git
cd path/to/nashsweeper
  • STEP 4: Edit the profile for client end to server end
# edit the two belowing profile 
# nashsweeper/nashsweeper-client/BackendServerInfo.json
# nashsweeper/nashsweeper-client-ipad/BackendServerInfo.json
{
    "backendIP": "http://127.0.0.1:5000/",
    "nodebridgeIP": "http://127.0.0.1:3000/",
    # change the backendIP from 127.0.0.1:5000 to your IP address
    # For example: In my home, my device IP is 192.168.1.104
    # and my backend port is 5000
    # so backendIP is: "backendIP": "http://192.168.1.104:5000/",
    "backendName":"Server Name",
    "backendOS":"Server OS",
    "backendCapacity":"Server Cap"
}
  • STEP 5: Build the images of nashsweeper
sudo docker-compose build
  • STEP 6: Run the containers
sudo docker-compose up -d
  • STEP 7: Stop nashsweeper
sudo docker-compose down

0x02 Software Architecture

Frontend User Interface Render

graph LR
App[App.vue]--Router.js-->HomePage(HomePage of PC)
HomePage-->SideBar(SideBar)
HomePage-->DataBarShow(DataBarShow)
SideBar--VueComponent-->PartA[PartA]
SideBar--VueComponent-->PartB[PartB]
PartB--TimeCom-->TimeCounterCom
PartB--NECom-->NEcounter
PartB--BRCom-->BRcounter
SideBar--VueComponent-->PartC[PartC]
DataBarShow--user_NE-->PartC-1[Part C-1]
DataBarShow--user_BR-->PartC-2[Part C-2]
DataBarShow--user_operation-->PartC-3[Part C-3]
DataBarShow--VueComponent-->PartD[PartD]
PartD--GameMainPart-->Checkerboard[Checkerboard]
DataBarShow--VueComponent-->PartE[PartE]
PartE--Gitee, Github Link-->ProjLink
PartE--GetPlayerRank-->PlayerRate
PartC-1--vueCom-->NEReview[NE Review]
PartC-2--vueCom-->BRReview[BR Review]
PartC-3--vueCom-->UserLog[User Log]
App--Router.js-->iPad(iPad)
iPad-->iPadCom[iPadCom]
iPadCom-->ComList[Components similar to the PC side]
Loading

Backend DataProcess

sequenceDiagram
    participant Nashsweeper_User
    participant Backend_Server
    participant Frontend_server

    Nashsweeper_User ->> Frontend_server: Visit http://<nashsweeperIP>:8082 through browser, request NS UI and Game Data
    Frontend_server -->> Backend_Server: Axios(method: "GET"), GameData, UserRank, etc.
    loop Generate game data
        Backend_Server -->> Backend_Server: if NE.length == 0
    end
    Backend_Server ->> Frontend_server: Return GameData and UserRank
    Frontend_server ->> Nashsweeper_User: Rendering the UI and GameData, UserRank
    loop User Playing the Game
        Nashsweeper_User -->> Nashsweeper_User: if NEset.length != NE.length
    end
Loading