Giter Site home page Giter Site logo

Design thoughts about flixball HOT 6 OPEN

mlutze avatar mlutze commented on August 17, 2024 1
Design thoughts

from flixball.

Comments (6)

JonathanStarup avatar JonathanStarup commented on August 17, 2024
  1. yes, my code has been missing some reorganization. I think all of our data structuring could use a rethink to avoid hassle, coupling, and redundancy.
  2. I agree in principle but i think that the board does not contain extranous information, maybe if it changes from its current definition.
  3. i think that should be possible right now quite easily, i can try it out next fine i code.
  4. i think both are valid but mutability should only be for performance. it certainly looks like a monadic pattern

from flixball.

mlutze avatar mlutze commented on August 17, 2024

Here's my current thought on GameState etc.

GameState currently has

  • states: Map[PlayerId, (Int32, Map[String, String])]
  • positions: Map[PlayerId, Position]
  • board: Board

And Board contains Tiles which contain Players which contain MoveLogic

I think we should essentially get rid of Player and instead store the relevant data in the maps.

So GameState becomes (states, positions, logics, board). And things dealing with Player instead deal with PlayerId.

Then we separate GameState into PublicState and PrivateState. This way we keep the states and logic of all the AIs separate from each other. So the getMove function for AIs has the signature: (Int32, Map[String, String]) -> PublicState -> ((Int32, Map[String, String]), Move)

from flixball.

JonathanStarup avatar JonathanStarup commented on August 17, 2024

I agree generally.

  • I still think the MoveLogic should be regioned, which removes the Int32, Map... and States map which simplifies things.
  • Our running of the board has become stateful but with the above change, why is it stateful? the positions map is just there for performance right? it can be computed from the board

from flixball.

mlutze avatar mlutze commented on August 17, 2024
* I still think the MoveLogic should be regioned, which removes the Int32, Map... and States map which simplifies things.

Yes, I agree if it can be made to work, but I am not yet convinced it can work :)

* Our running of the board has become stateful but with the above change, why is it stateful? the positions map is just there for performance right? it can be computed from the board

Positions is indeed redundant. I don't totally understand what you mean by stateful though. Here I'm mostly just rearranging where the data is located.

from flixball.

mlutze avatar mlutze commented on August 17, 2024

I've run into a problem with the Impure to Pure MoveLogic function.

    type alias MutMoveLogic[m: Region -> Type, r: Region] =
        (GameState, PlayerId, m[r]) -> Move \ r

    def toMoveLogic(logic: MutMoveLogic[m, r]): MoveLogic with State[a] = {
        def f(gs, id, state) = region reg {
            // call logic() with conversions
        }
    }

The issue is that here, we want the r of MutMoveLogic[m, r] to unify with reg. But r is already bound by the function. For example we could call toMoveLogic with logic: MutMoveLogic[T, Static] which would never unify with reg.

What we really need is a rank-2 type, so MutMoveLogic is instead MutMoveLogic[m: Region -> Type] = forall r, (GameState, PlayerId, m[r]) -> Move \ r. But Flix doesn't have rank-2 types, so we need some kind of workaround.

from flixball.

JonathanStarup avatar JonathanStarup commented on August 17, 2024

I've run into a problem with the Impure to Pure MoveLogic function.

    type alias MutMoveLogic[m: Region -> Type, r: Region] =
        (GameState, PlayerId, m[r]) -> Move \ r

    def toMoveLogic(logic: MutMoveLogic[m, r]): MoveLogic with State[a] = {
        def f(gs, id, state) = region reg {
            // call logic() with conversions
        }
    }

The issue is that here, we want the r of MutMoveLogic[m, r] to unify with reg. But r is already bound by the function. For example we could call toMoveLogic with logic: MutMoveLogic[T, Static] which would never unify with reg.

What we really need is a rank-2 type, so MutMoveLogic is instead MutMoveLogic[m: Region -> Type] = forall r, (GameState, PlayerId, m[r]) -> Move \ r. But Flix doesn't have rank-2 types, so we need some kind of workaround.

yea I had this problem too. difficult to solve. In my attempt, I added a region argument to toMoveLogic such that the caller, which hopefully can instantiate the region type parameter, can make them have the same region.

from flixball.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.