Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snek pathfinding #141

Open
kubikowski opened this issue Jun 26, 2021 · 1 comment
Open

snek pathfinding #141

kubikowski opened this issue Jun 26, 2021 · 1 comment
Labels
code: Angular 🅰️ changes to the Angular application type: Improvement 🎨 general improvements to the code format & structure

Comments

@kubikowski
Copy link
Owner

Affected Version: v0.4.3

Description:

The current snek auto solver makes directional decisions based solely on immediate availability. Once the snek gets to a length (I naively believe that it is currently around 20-50), the solver has a tendency of cordoning off enclosed regions, then turning in to them. This action, of course, ends the game.

Some optimizations could be made within the confines of directional immediacy, for instance the following:

  • The solver could prefer moving adjacent to existing walls and snek nodes when available. The effect would be that the snek would follow its own body as much as possible, which would reduce the likelihood of creating enclosed regions at any given moment. This may increase the average game length to a certain extent, but it is not a viable late-game solution on its own.

Ultimately, any optimizations made for immediate directional preferences have a key flaw. They are making unfounded assumptions about future game states. The most viable long-term solution is to add some form of path-finding.

Suggested Changes:

Replace the existing solver with a snek path-finding service.

This service will create a tree of possible futures based on directional inputs, and weight each leaf node with some optimization and safety metrics. It will grow this tree until it has identified an optimal and safe path to the next fud node.

Upon choosing a path (or set of paths) to the fud node, it could continue path-finding for safety to a further depth, equivalent to the current length of the snek.

Once per game counter it will provide the next direction input, based on its current projection of the most optimal and safe path.

@kubikowski kubikowski added code: Angular 🅰️ changes to the Angular application type: Improvement 🎨 general improvements to the code format & structure labels Jun 26, 2021
kubikowski added a commit that referenced this issue Jul 20, 2021
kubikowski added a commit that referenced this issue Jul 20, 2021
kubikowski added a commit that referenced this issue Sep 20, 2021
* added a more robust set of colors  (#126)

* added a more robust set of colors

* downgraded dyslexic-text bindings for static content, added filler text in sidebar header

* ci: version bump to 0.3.18

* minified icons & added goat (#128)

* added goat icon

* Minified the rest of the icons

* ci: version bump to 0.3.19

* Added external icons to MatIconRegistry (#129)

* ci: version bump to 0.3.20

* deploy with current version & fix tag prefix (#130)

* ci: version bump to v0.3.21

* second pass at deploying with a correct version number (#131)

rewrote readme

* ci: version bump to v0.3.22

* renamed PageNotFound → NotFound (#132)

* renamed PageNotFound → NotFound

* No more compiler warnings

* ci: version bump to v0.3.23

* build(deps-dev): bump @angular/cli from 12.0.5 to 12.1.0 (#135)

* build(deps-dev): bump @angular-devkit/build-angular (#136)

* feature: decentralized snek logic (#137)

* moved snek runtime logic into services

* Angular Upgrade: 12.0.5 → 12.1.0

* added SnekGameState with event emitting

* renamed SnekService → SnekStateService, it is now called by all other services

* optimised imports

* ci: version bump to v0.4.0

* componentized the snek (#138)

* ci: version bump to v0.4.1

* improved mat typography (#139)

* improved mat typography

* Increased options for fetched garamond

* ci: version bump to v0.4.2

* added basic snek auto solver (#140)

* added basic snek auto solver

* Fixed unit tests

* ci: version bump to v0.4.3

* moved snek score into gameState (#142)

* moved score to be a member of SnekGameState

* readonly provided constructor values

* ci: version bump to v0.4.4

* Moved files into directories

* ci: version bump to v0.4.5

* build(deps-dev): bump @types/node from 15.12.4 to 15.12.5 (#143)

* build(deps-dev): bump typescript from 4.2.4 to 4.3.4 (#144)

* refactored snek results to include gameOverMessage (#145)

* Added gameOverMessage to results dialog

* moved material overrides into individual files

* filter empty game state logs

* ci: version bump to v0.4.6

* improved mobile page layouts (#146)

* Replaced project stack with status updates

* Fleshed out gong generic cards, simplified card layouts.

* refactored page layouts

* Added a gong page title; added a snek warning if you render under res

* proofreading

* ci: version bump to v0.4.7

* improved snek resolution management (#147)

* improved media queries

* added SnekResolutionService

* refactored snekResolution

* attempting to fix imports

* removed console warnings on suboptimal size

* added line height to mat card titles

* proofreading

* ci: version bump to v0.4.8

* build(deps-dev): bump typescript from 4.3.4 to 4.3.5 (#148)

* added TitleService (#149)

* refactored snek grid resolution out of state service

* updated readme to include RxJS

* added TitleService

* ci: version bump to v0.4.9

* build(deps-dev): bump @types/node from 15.12.5 to 15.14.0 (#150)

* build(deps-dev): bump @angular-devkit/build-angular (#152)

* build(deps-dev): bump jasmine-core from 3.7.1 to 3.8.0 (#153)

* build(deps-dev): bump @angular/cli from 12.1.0 to 12.1.1 (#151)

* refactored modules (#154)

* optimised modules

* Angular Upgrade: 12.1.0 → 12.1.1 (core)

* Angular Upgrade: 12.1.0 → 12.1.1 (material)

* ci: version bump to v0.4.10

* feature: mobile snek with hammerjs (#155)

* feature: mobile snek with hammerjs

* import Hammer

* renamed → SnekUserInputService

* ci: version bump to v0.5.0

* build(deps-dev): bump @types/jasmine from 3.7.7 to 3.7.8 (#157)

* build(deps-dev): bump @types/jasminewd2 from 2.0.9 to 2.0.10 (#158)

* build(deps-dev): bump @types/hammerjs from 2.0.39 to 2.0.40 (#159)

* First attempt at implementing a joystick with nipplejs (#161)

* ci: version bump to v0.5.1

* improved joystick options (#162)

* First attempt at implementing a joystick with nipplejs

* improved joystick options

* ci: version bump to v0.5.2

* build(deps-dev): bump @types/jasmine from 3.7.8 to 3.8.1 (#164)

* build(deps-dev): bump @types/node from 15.14.0 to 16.3.0 (#163)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 15.14.0 to 16.3.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* permanently sticking with joystick (#165)

* npm audit fix

* fixed joystick overflow over board grid

* formally remove hammerjs

* ci: version bump to v0.5.3

* added floating background shapes (#166)

* fixed sidebar item styling

* added svg shapes named after sins

* Added background component with floating icons

* ci: version bump to v0.5.4

* build(deps-dev): bump ts-node from 10.0.0 to 10.1.0 (#167)

* build(deps-dev): bump @types/node from 16.3.0 to 16.3.1 (#168)

* build(deps-dev): bump karma-jasmine-html-reporter from 1.6.0 to 1.7.0 (#169)

* moving background settings (#170)

* optimized background subsccription

* more clouds

* Beginning to move the logic into a moving-background service

* getting there

* clamp user input

* improved naming conventions

* ci: version bump to v0.5.5

* build(deps-dev): bump @types/node from 16.3.1 to 16.3.2 (#171)

* renamed sins.constant (#172)

* ci: version bump to v0.5.6

* build(deps-dev): bump @angular/cli from 12.1.1 to 12.1.2 (#173)

* Angular Upgrade: 12.1.1 → 12.1.2 (#176)

* canvas background (#175)

* rudimentary canvas background

* added a rudimentary background canvas service

* added a circle model which redraws on animation frames

* added a rudimentary fps service

* added a mousePosition and improved FPS monitor with averaging

* fixed mousemove

* ColorsService uses behavior subjects

* added missing subsctiption.unsubscribe() to services

* added circle delta radius

* ci: version bump to v0.5.7

* build(deps-dev): bump @types/node from 16.3.2 to 16.3.3 (#177)

* canvas pixel density (#178)

* canvas accounts for pixel density

* @ViewChild set sidenav

* canvas accounts for header offset

* ci: version bump to v0.5.8

* remove out of bound circles on resize (#179)

* @ViewChild static set

* @ViewChild set fails initial getBoundingClientRect

* remove out of bound circles on resize

* ci: version bump to v0.5.9

* #141: stop hitting yourself (#180)

* ci: version bump to v0.5.10

* dedicated background page, where all you can see is noise (#181)

* dedicated background page, where all you can see is noise

* added snek.svg

* fixed page overflow

* pure noise

* ci: version bump to v0.5.11

* feature: restructured angular app (#182)

* Restructured Angular App into `core`, `features`, and `pages`

* added a dedicated snek page, renamed page files

* ci: version bump to v0.6.0

* build(deps-dev): bump @types/node from 16.3.3 to 16.4.0 (#183)

* fix dyslexic-text bias (#184)

* fix dyslexic-text bias

* clamp dyslexiaAmount

* ci: version bump to v0.6.1

* build(deps-dev): bump @angular-devkit/build-angular (#185)

* build(deps-dev): bump @angular/cli from 12.1.2 to 12.1.3 (#186)

* build(deps-dev): bump @types/node from 16.4.0 to 16.4.1 (#187)

* Angular Upgrade: 12.1.2 → 12.1.3 (#188)

* snek command queue (#189)

* added an preliminary, limited command queue
it currently fails to filter subsequent inputs on validity

* added direction change validity checks

* SnekDirection namespace

* ci: version bump to v0.6.2

* build(deps-dev): bump @types/node from 16.4.1 to 16.4.3 (#190)

* build(deps-dev): bump @types/node from 16.4.3 to 16.4.5 (#191)

* build(deps-dev): bump @angular-devkit/build-angular (#192)

* build(deps-dev): bump @types/node from 16.4.5 to 16.4.6 (#194)

* build(deps-dev): bump @angular/cli from 12.1.3 to 12.1.4 (#193)

* build(deps-dev): bump @types/jasmine from 3.8.1 to 3.8.2 (#195)

* Angular Upgrade: 12.1.3 → 12.1.4  (#196)

* semantic changes to title service

* removed whitespace

* Angular Upgrade: 12.1.3 → 12.1.4

* reformatted package-lock to use tabs. we'll see how long this lasts

* updated readme to include angular upgrade script

* ci: version bump to v0.6.3

* about page: humble beginnings (#197)

* The beginnings of the About page

* Updated PinkPalette with some Pantone TCX colors

* Updated about.component.html

* fixed build

* refactored about to current standards (v0.6.3) (#199)

* deleted accidental files

* renamed files to `about-page`

* brought the existing about page up to current standards

* and some padding for good taste

* build(deps-dev): bump @types/node from 16.4.6 to 16.4.7 (#200)

* added feature flags (#201)

* added route feature flags

* semantic consistency

* ci: version bump to v0.7.0

* refactored about to current standards (v0.7.0) (#202)

* reimagined the about page layout
added an (un)professional headhot to src control

* fix linting

* feature flagged the about page

* removed comment

* reverted pink palette (#203)

* ci: version bump to v0.8.0

* fix minor version bump wording (#204)

fix minor version bump wording

* ci: version bump to v0.8.1

* attempting to sign `Automated Version Bump` commits (#205)

* attempting to sign `Automated Version Bump` commits

* added `gpg.program` to bump version git config (#206)

* testing which gpg

* git config list

* added `gpg.program` to git config

* testing `echo "no-tty"` (#207)

* testing echo "no-tty"

* deleted test file

* temp fix: unsigned version bump (#209)

* ci: version bump to v0.8.2

* added favicon (#210)

* added favicon & scripts to generate images from svg

* favicons are so wack

* delete duplicate favicon

* this should be fine

* fix comments

* ci: version bump to v0.8.3

* build(deps-dev): bump @types/node from 16.4.7 to 16.4.10 (#211)

* refactored favicons (#212)

* fixed webmanifest, simplified icon

* standardised icon colors

* added a development favicon

* ci: version bump to v0.8.4

* refactored `core/browser` services (#213)

* added favicon ref enum

* moved services into `core/browser`

* missed a service rename

* converted `FaviconService` to use `Renderer2`

* converted `ColorsService` to use `Renderer2`

* adds sizes any to favicon.svg

* ci: version bump to v0.8.5

* fixed `apple-touch-icon` rel (#214)

* fixed apple-touch-icon

* fix `removeFavicon` check

* ci: version bump to v0.8.6

* configured `firebase` with `@angular/fire` (#215)

* ci: version bump to v0.8.7

* build(deps): bump tar from 6.1.0 to 6.1.5 (#216)

* build(deps-dev): bump @types/node from 16.4.10 to 16.4.11 (#217)

* build(deps-dev): bump @angular-devkit/build-angular (#218)

* build(deps-dev): bump @types/node from 16.4.11 to 16.4.12 (#220)

* build(deps-dev): bump @angular/cli from 12.1.4 to 12.2.0 (#219)

* build(deps-dev): bump @types/node from 16.4.12 to 16.4.13 (#221)

* build(deps): bump firebase from 8.8.1 to 8.9.0 (#222)

* Angular Upgrade: 12.1.4 → 12.2.0 (#223)

* Angular Upgrade: 12.1.4 → 12.2.0

* specify tilde semver range for npm packages

* added about contact card (#224)

* added contact email in a new card. I really need to learn how to style a resume

* ci: version bump to v0.8.8

* added `.gitattributes` to enforce LF line endings (#225)

* ci: version bump to v0.8.9

* reformatted `.idea` files (#226)

* ci: version bump to v0.8.10

* build(deps-dev): bump ts-node from 10.1.0 to 10.2.0 (#227)

* build(deps): bump firebase from 8.9.0 to 8.9.1 (#228)

* build(deps): bump tslib from 2.3.0 to 2.3.1 (#229)

* build(deps-dev): bump @angular-devkit/build-angular (#230)

* build(deps-dev): bump @angular/cli from 12.2.0 to 12.2.1 (#231)

* build(deps-dev): bump @types/node from 16.4.13 to 16.6.0 (#232)

* build(deps): bump path-parse from 1.0.6 to 1.0.7 (#233)

* build(deps-dev): bump @types/node from 16.6.0 to 16.6.1 (#234)

* Angular Upgrade: 12.2.0 → 12.2.1 (#235)

* Angular Upgrade: 12.2.0 → 12.2.1

* npm audit fix

* update `deploy` action to use `production` environment (#236)

* ci: version bump to v0.8.11

* added `mapToVoid` pipe (#237)

* ci: version bump to v0.8.12

* converted `karma` to TS & removed `protractor` (#238)

* converted `karma` config to TS

* removed unused e2e platform

* ci: version bump to v0.8.13

* use published `rxjs-observed-decorator` (#239)

* ci: version bump to v0.8.14

* build(deps-dev): bump ts-node from 10.2.0 to 10.2.1 (#240)

* build(deps): bump firebase from 8.9.1 to 8.10.0 (#244)

* build(deps-dev): bump @angular-devkit/build-angular (#243)

* build(deps-dev): bump @types/node from 16.6.1 to 16.6.2 (#242)

* build(deps-dev): bump @angular/cli from 12.2.1 to 12.2.2 (#241)

* build(deps-dev): bump jasmine-core from 3.8.0 to 3.9.0 (#245)

* build(deps-dev): bump @types/node from 16.6.2 to 16.7.1 (#246)

* build(deps-dev): bump @types/node from 16.7.1 to 16.7.2 (#247)

* build(deps-dev): bump @angular/cli from 12.2.2 to 12.2.3 (#248)

* build(deps-dev): bump @angular-devkit/build-angular (#249)

* build(deps-dev): bump @types/node from 16.7.2 to 16.7.6 (#250)

* build(deps-dev): bump @types/node from 16.7.6 to 16.7.8 (#251)

* build(deps): bump tar from 6.1.5 to 6.1.11 (#252)

* build(deps-dev): bump @types/node from 16.7.8 to 16.7.10 (#253)

* build(deps-dev): bump @angular-devkit/build-angular (#254)

* build(deps-dev): bump @types/jasmine from 3.8.2 to 3.9.0 (#256)

* build(deps-dev): bump @angular/cli from 12.2.3 to 12.2.4 (#255)

* build(deps-dev): bump @types/node from 16.7.10 to 16.7.13 (#257)

* build(deps-dev): bump @angular-devkit/build-angular (#258)

* build(deps-dev): bump @angular/cli from 12.2.4 to 12.2.5 (#259)

* build(deps-dev): bump @types/node from 16.7.13 to 16.9.0 (#260)

* build(deps-dev): bump @types/node from 16.9.0 to 16.9.1 (#261)

* build(deps-dev): bump @types/jasmine from 3.9.0 to 3.9.1 (#262)

* build(deps-dev): bump @angular-devkit/build-angular (#263)

* build(deps-dev): bump @types/node from 16.9.1 to 16.9.2 (#265)

* build(deps-dev): bump @angular/cli from 12.2.5 to 12.2.6 (#264)

* Angular Upgrade: 12.2.1 → 12.2.6 (#266)

* Fixed app build

* Moved page implementation into `features`

Co-authored-by: Automated Version Bump <gh-action-bump-version@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@kubikowski
Copy link
Owner Author

Implementation Notes:

A pathfinding algorithm could be implemented using Jordan Curves to evaluate whether a given path would create enclosed regions. And the pathfinding algorithm would thus generally prefer against paths which would create these regions.

Enclosed regions cause the majority of safety concerns for the board state. As mentioned above, the snek can become trapped in an enclosed region. If the snek length is greater than the total available space in any region, it can not escape that region. Which ultimately results in the game's ending.

Other things which should be evaluated if a path would create an enclosed region are:

  1. The lifetime of the enclosed region.
    a. How many turns will it take before the region is no longer enclosed?
  2. The size of the enclosed region.
    a. How large is the area of the region currently?
    b. Will it's area change over time?
  3. The risk associated with the enclosed region.
    a. Is the snek head capable of & otherwise likely to return near that region while it still exists?

Jordan Curves present a solution for identifying enclosed regions. This would handle the prominent safety concerns associated with the pathfinding algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code: Angular 🅰️ changes to the Angular application type: Improvement 🎨 general improvements to the code format & structure
Projects
None yet
Development

No branches or pull requests

1 participant