Code Monkey home page Code Monkey logo

poker-maison's Introduction

Poker Maison

A multiplayer app crafted with Haskell and React

https://news.ycombinator.com/item?id=20653278

License: Unlicense

alt text

Get everything running with Docker

Prerequisites

In order to use Docker have the following installed.

Firstly start Docker Machine

docker-machine start

Then set the correct variables in your terminal so you can connect to Docker Machine

eval $(docker-machine env)

Now build the images. This will take a while.

docker-compose up

Now go navigate to http://192.168.99.100:3000 in your browser and the app should be running.

The above ip address is the one for your docker-machine VM if you are on the default settings. By default docker-machine doesn't serve localhost but instead uses 192.168.99.100 as the host.

You can simulate multiple players in the same game on on your machine if you navigate to the above url in a few different browser tabs. Eac time you open up a new tab just remember to log out after you have signed in as the browser will cache the access_token for the last logged in user for each new tab as URL is the same.

Common Docker Problems

Docker has the wrong TLS setting

If you get the error below then Docker Compose is not using the correct TLS version.

Building web
ERROR: SSL error: HTTPSConnectionPool(host='192.168.99.100', port=2376): Max retries exceeded with url: /v1.30/build?q=False&pull=False&t=server_web&nocache=False&forcerm=False&rm=True (Caused by SSLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:727)'),))

You can fix this by setting the following environment variable with the correct TLS version.

export COMPOSE_TLS_VERSION=TLSv1_2

Container runs out of memory

If the server docker container runs out of memory whilst building. Whis would look like this.

--  While building package Cabal-2.4.1.0 using:
      /root/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.4.0.1 build --ghc-options ""
    Process exited with code: ExitFailure (-9) (THIS MAY INDICATE OUT OF MEMORY)

Then set increase the memory available to the VM you are using for docker-machine. Assuming your VM is named "default", run:

docker-machine stop default
VBoxManage modifyvm default --memory 4096
docker-machine start default

Slow builds

If you want to speed up builds then replace n in the command below with the number of cores your machine has and run the command. The command below assumes that "default" is the name of the VM Docker Machine is using.

docker-machine stop default
VBoxManage modifyvm default --cpus n
docker-machine start default

Building locally from scratch.

The following steps are based on an Ubuntu distribution.

Back End

Firstly make sure you have ghc and stack installed in order to compile the back end written in Haskell. If you need to install the Haskell platform then run

curl -sSL https://get.haskellstack.org/ | sh

Secondly install libpq (c bindings to postgres)

sudo apt-get install libpq-dev

Next install redis.

sudo apt-get install redis

Navigate to the server/ directory.

cd server

Compile the back end poker server.

stack build

Now we need to set some config.

Ensure postgresql 10 is installed and running.

Set the env var so that the server has the postgresql connection string. Of course you will need to change the db connection parameters below to match your local database.

export dbConnStr='host=0.0.0.0 port=5432 user=tom dbname=pokerdbtest password=tom

Set env variable with the secret key for generating auth tokens. Note that this secret must be 32 characters long or it won't work.

export secret="changeme077cf4e7441c32d2d0a86b4c"

Lastly ensure redis-server is running in the background on default port

redis-server

Now run the server locally. The default user API port is 8000 and websocket port is 5000.

stack run

Front End

Install node version 10.16.3 and then install yarn globally

Install a required system dependency for node-sass .

sudo apt-get install libpng-dev

Navigate to the client/ directory with

cd client

Then just run.

yarn start

Now you are ready to play poker!

Simulating a multiplayer game locally

You may want to play against yourself when you are developing locally so just run the clients on two separate ports.

In your first terminal run

PORT=8001 yarn start

Then open another terminal and run

PORT=8002 yarn start

Now just open two tabs in your browser navigating to

localhost:8001

and

localhost:8002

Running Tests

To run the test suite on the backend which has over a hundred tests

cd server && stack test

Contributions Welcome

Have a look at the issues if you want some starting ideas on how to get involved.

Feel free to open any issues with potential enhancements or bugs you have found.

License

This is free and unencumbered software released into the public domain.
For more information, please refer to the UNLICENSE file or unlicense.org.

poker-maison's People

Contributors

therewillbecode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

poker-maison's Issues

GetProfile API Endpoint should also give some basic game stats for the user

The type representing the Servant API endpoint for getting the User's Profile is here

The API Endpoint handler for fetching a user's profile is here

It would be a good idea to add some basic game stats such as Hands played, total profit/loss over career, Big Blind win rate etc. This way players can have more insight into how they are playing.

You will of course need to add new record fields to the UserProfile type.

Player's Max Bet Should Be Limited

Limit a player's max bet according to either their chip count or the next largest player in the hand's chipcount. Which ever is smaller.

This would prevent the current bug where a player can raise more than an opponents chip stack in a 1v1.

Remove action buttons from game UI which represent invalid actions

The game view in the UI presented to a player when sat at the table has a panel of buttons representing game actions.

Currently only two sets of buttons are shown for players depending whether they are sat in a game or not.

What we want is to only show buttons with actions which are valid for the given game state.

Here is an example. if a player has raised before you, then you will still be presented with a check button. As a check action isn't possible during a round after a previous player has raised in the game of poker. This button shouldn't be shown to the player in such a situation.

The front end has a Redux store which contains the game state as a JS object. So the task would be to add action validation functions and alter the game action panel React component so that only buttons with valid actions according to the rules of poker are shown to players.

To help you determine which actions are valid depending on certain game states then look at the ActionValidation.hs file on the back end. Essentially you would need to rewrite most of this logic in Javascript and put this validation logic in the selectors.js file on the front end.

Add more Lobby tables when existing ones become full.

The amount of tables in the game lobby should automatically adjust when the existing tables begin to fill up.

A sensible default would be to say that there should be at least two tables with free seats which can be taken.

Feel free to add this logic to the Lobby.hs file.

Add support for side pots

The core of the poker game logic lives in Game.hs.

At the moment only single pots are supported.

What we need is side pots.

For an explanation of how they work check this out.

Connect remotely

When I am making requests to create a new user or login, its trying to connect to a localhost url.. how do define the URL or or IP of the server?

Thanks!

cd server && stack run gives error

tuguldur@tuguldur-Inspiron-3537:~/Downloads/poker-maison-master/server$ stack run
poker-server-exe: Missing dbConnStr in env
CallStack (from HasCallStack):
error, called at src/Env.hs:46:18 in poker-server-0.1.0.0-1noFjA1fxcLE6B4gEAhgPz:Env

User Folds Automatically Too Quickly

I just tried to spin this up for a few mates to play however after I place big and small blind it would just auto fold the user who took more than about 1 seconds.

I've tried looking through the code but not sure what is going on or why it is timing out so quickly.

Player state becomes undefined then just folds the user and moves on.

Module not found: Error: Can't resolve './Counter.bs'

ERROR in ./app/components/Profile.js
Module not found: Error: Can't resolve './Counter.bs' in '/home/user/haskell-poker/client/app/components'
@ ./app/components/Profile.js 3:18-41
@ ./app/containers/ProfileContainer.js
@ ./app/components/App.js
@ ./app/containers/AppContainer.js
@ ./app/app.js
@ multi eventsource-polyfill webpack-hot-middleware/client?reload=true ./app/app.js
「wdm」: Failed to compile.

Monthly League Format?

Have a monthly league where placing in a good position grants some kind of badge for players.

This would be a simple incentive for competitive play despite the lack of money involved.

Extracting holdem game logic into separate package

We've talked in the past (dunno if you remember - 3 years ago maybe?).

Summary

Thanks for the great project :) Incoming wall of text, but I hope it is all to the point. I would like to migrate poker-maison to use a shared library for core poker type declarations (in src/Poker.Types) and for holdem game logic (src/Poker.Game.*). In general there is no need for each programmer to reimplement poker types and holdem (or any poker game) logic, and so if we get one solid and collaborated-upon set of libraries going, we'll have a better haskell-poker ecosystem! :)

My goal for these libraries is to be a good example of Haskell code. Nothing too fancy, but also nothing too simple, using the most common haskell features such as lens and mtl, so that an intermediate haskeller would feel comfortable and a beginner could come in without being overwhelmed.

I have already implemented the lion's share of the library, so I am here to check if you would be okay with migrating poker-maison to use my code. I have tested poker-maison with some of the migration, and it all looks good as far as I can tell.

What it would look like for poker-maison

poker-maison would use the new library for stuff like:

  • core poker types
  • next available actions for main street actions (preflop thru river)
  • stack sizes
  • basic poker types

Some things are not yet implemented not yet support (but would be added at a later date, likely by using your logic, if that's okay with you):

  • blind posting
  • showdown

Some notable differences:

  • I, as a rule, don't override Show or Read instances, since the libraries are aimed for all to use. Instead I implement pretty-simple's Pretty class, which I see you already use anyway.
  • I don't override Eq/Ord anywhere, since these instances can be used sometimes for Map and occasionally for serialisation. This only caused one minor issue with migrating poker-maison (see Poker.Game.Hands.sortByLength), which is easily fixed.
  • My goal is to have hand phase separation, so the game state type will be unique for each of blind-posting, post-card-deal (preflop thru river), and showdown (3 game state types in total).
  • My library is polymorphic in the bet type, but this would hidden from your code almost completely.
  • My library code uses State monad lens combinators extensively, but no other fanciness, and isn't too long (around 1000 lines excluding tests).
  • My test coverage is not yet a superset of your tests. Before merging, I would translate all your tests into my codebase (I already started the process locally). My code is tested and was tested by running around 10,000ish hands from my Bovada database through my holdem engine. The tests test both that all actions in the DB were accepted by my holdem engine, and that test-runner-generated invalid actions returned an error for all acts for all hands. I will also be augmenting these tests with a 1,000,000 hand database (including heads-up hands) from PokerStars once I have a parser for PokerStars hand histories.
  • I don't account for table actions such as Timeouts and LeaveSeats, which would be translated to my "BetAction", which are the in-a-vacuum available actions to a player. For example, your "Action" type might look something like the following:
data Action
  = SitDown Player -- doesnt progress the game
  | LeaveSeat' -- doesnt progress the game
  | PostBlind Blind
  | ShowHand
  | MuckHand
  | SitOut
  | SitIn
  | Timeout
  | FromBetAction BetAction

The migration process

I would be happy to do this migration all myself, and do so incrementally to make it more reviewable for you! I don't expect the patches to be too involved/arduous.

If you're open to the process, the only thing that I would ask from you would be whether I could make changes to the build system for poker-maison. In particular I was having trouble with having a good IDE setup, likely because of the following github issue haskell/haskell-language-server#1822. Would you be okay with a cabal based build instead of stack? The trade off would be slightly more verbose builds (you have to add each file to the .cabal file) which is definitely annoying, but as a reward we don't get an infuriating bug that means you have to persistently restart the IDE each time you edit library code while working on a test.

The process would overall look like this:

  • integrate with poker-base, which is here. This code will definitely experience more cleanups, and I'd like to get to 90+% test coverage (up from ~70%)
  • integrate with poker-game which lives here. This would be the harder part, but I can show in a PR maybe this weekend?

Unable to Build

Windows 10
Docker version 19.03.8, build afacb8b
Help!

PS C:\Users\DELL-XPS730x\Desktop\ten-poker-master> docker-compose up
Building server
Step 1/8 : FROM fpco/stack-build-small
---> 5aab45466769
Step 2/8 : RUN mkdir -p /app
---> Using cache
---> d464935159cc
Step 3/8 : COPY . /app
---> Using cache
---> c6b5323f889e
Step 4/8 : WORKDIR /app
---> Using cache
---> e93007258dd8
Step 5/8 : RUN apt-get update && apt-get install libpq-dev lzma-dev libpq-dev -yy
---> Using cache
---> c5fa874e24ac
Step 6/8 : RUN stack build --only-dependencies
---> Running in 7f5d4fb23662
Segmentation fault
ERROR: Service 'server' failed to build: The command '/bin/sh -c stack build --only-dependencies' returned a non-zero code: 139
PS C:\Users\DELL-XPS730x\Desktop\ten-poker-master>

Do not /login

Status: 401 Unauthorized 0.020413627s

In everything wrote this, /register is working, but already wrote that

why on token generation write: Left KeySizeTooSmall ???

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.