Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
docs: documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Dec 17, 2020
1 parent 00f124e commit c535d0d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
56 changes: 47 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?&style=for-the-badge&logoColor=white)](https://github.com/semantic-release/semantic-release)


# Usage
1) Donwload and run executable (for your OS) in Releases.
1) Application is hosted at `localhost:3000`.
1) Click start
1) Wait until some training is done (Calculations done is recommended to be at least 20,000)
1) Click stop
1) Click play to see results (game is played between two best bots)
1) Training can be resumed by clicking Start again

# compiling
## requirements
Expand All @@ -37,11 +45,47 @@
- ```yarn ci``` or ```yarn install``` (if not called already)
- ```yarn dev```

# Running
open Start.exe

## Application

## Usage
This project was changed from racing game into duel game of two bots. (See old).

### UI

Left side contains list of cards with best bots. Left side contains name of bot, blue bar with bonus and red bar with health. Right sides contains number of games bot played, number of bots wins, number of childrens (mutated compies of this bot) and steps from it's last game.
Right side contains player which replays duel of best two bots.


### Evolutionary algorithm

First version of this project used game for one player. Newer version introduces duel game, which cause problems with evolving bots. Instead of incrementaly improving bots fitness and approximating some theoretical fitness boundary, bots was oscilating in low and high values. It was probably caused by switching between two (or possibly more) strategies, instead of improving existing ones.

Problem with oscilating was so unexpected for me and I didn't manage to find online solution for this kind of problem using neural nets and evolutinary algorithms. So I have used method which does not use generation but is pruning and creating new bot's in one same population (method probably called _live learning_ or similar).

Despite the fact of using method of learning that better suits this particular game problem, training works best with used super parameters inside source of this project and even minor tweak in value of some of super parameters can make learning process fail. Suggested next step to improve learning process would be using some other machine learning method as meta learning to find best super parameters for this project.

Bot has _sensor*2 + 2_ neural net input values. Each sensor has type of detected object and range of that detection. Last two inputs are bots health and cooldown for shooting weapon.

#### Algorithm

Every bot has it's own health and bonus score. Bot's health is increased proportionally to health at end of each game. If bots health exceedes max-health, exceeding healths is added into bonus score instead. score is also increased when population is low (and lowered when population is high), so population can be kept in comfort range for training.

Algorithm step
1) Select two random bots ramdomly. Using weighted random -> weight is increased by: steps from last game, wins and other bot properties.
1) Play game with selected bots
1) Increase/Lower their health base on game result.
1) Transfer exceeding health into bonus.
1) Remove bots with no health.
1) Reset bonus metter and create mutated copy of bot for bots with maxed bonus

### Game

Each player is in his corner facing into center of map at start of each game. Bots has sensor attached asi inputs to their neural nets. Players health decreases each game step (motivation for bots to play aggressive -> faster the game is, lower the damage bot gets from game itself). Player can walk straight, rotate and shoot. Bullets can bounce and their damage is proportional to their speed. Motionless bullets are destroyed.


## old (racing) version documentation

Code documented in this section is already deleted. This documetation is only for comparisson with newer version of bot.

Learning steering car inside 2D using genetic algorithm

Expand All @@ -66,9 +110,3 @@ controls:

Pressing Start will start algorithmic calculations (can take some time). Plot wiht maximal fitnesses is shown when algorithm is done running.

Clicking item in list will start replay


possible inspiration:
https://github.com/wagenaartje/neataptic
https://github.com/CodeReclaimers/neat-python
2 changes: 1 addition & 1 deletion ui/src/logic/gameAi/GameAiEval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector } from "matter-js";
import { IANNInitParams, NeuralNet } from "../ai/nn/nn";
import { EGameStateObjectType, Game, GameInputPlayer, GameSettings, GameState, SensorPoint } from "../game/game";
import { EGameStateObjectType, Game, GameInputPlayer, GameSettings, SensorPoint } from "../game/game";


export type InitializeRandomBotParams = {
Expand Down

0 comments on commit c535d0d

Please sign in to comment.