Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop', 0.5 stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-bondar committed May 13, 2018
2 parents ca69054 + 404530b commit 74f72f0
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 80 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ List of implemented features:
- time delayed actions
- fade on button click
- bottom & up seatbolds
- detecting end of game
- automove on timebank end
- hightlighting of active player
- calculation of possible actions
- autoskip when no action is required
- handling bet rounds until showdown
- detecting winner(-s) and awarding them
- detecting & comparing of poker combinations
- *another not really cool stuff*

Expand All @@ -31,13 +34,13 @@ List of implemented features:
## Status

One phrase review: \
*Almost done ... base version*
*Base version seemed to be done*

Nothing really complete here yet,
but you can watch the flop, do some moves and play to
your heart content with a slider.
Release candidate for base version,
you can play to your heart content versus yourself,
although some bugs are sneaking nearby, probably.

Developing ...
Developing AI ...

![serious coding](/docs/images/serious%20coding.gif)

Expand All @@ -62,3 +65,5 @@ to verify results.
For launching tests:

`stack test`

*Don't even try to run if you don't know what you're exactly doing!*
Binary file added img/text/loss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/text/win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lambdem-poker.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: lambdem-poker
version: 0.4
version: 0.5
synopsis: Poker client
-- description:
homepage: https://github.com/cmc-haskell-2018/lambdem-poker
Expand Down
29 changes: 18 additions & 11 deletions src/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Poker.Logic.Dealer
import Poker.Logic.Trading
import Poker.Logic.Types

import Debug.Trace
--import Debug.Trace

-------------------------------------------------------------------------------
-- * Game launch related functions
Expand Down Expand Up @@ -47,6 +47,7 @@ createTableScreenWith generator imgs = TableScreen
, players =
[Player Human " Hero" 1500 SB Bottom Nothing False False 0 (Move Waiting 0) 0,
Player Human "Opponent" 1500 BB Top Nothing True False 0 (Move Waiting 0) 0]
, hero = " Hero"
, street = Preflop
, handCount = 1
, dealer = Bottom
Expand All @@ -64,8 +65,12 @@ createTableScreenWith generator imgs = TableScreen

-- | Update game parameters depending on game state.
updateGame :: Float -> TableScreen -> TableScreen
updateGame timePassed screen
| state screen == Dealing_Hand =
updateGame timePassed screen
| state screen == Start_Hand =
if (checkGameEnd $ players screen)
then screen { state = Finish_Game }
else screen { state = Dealing_Hand }
| state screen == Dealing_Hand =
if (timer screen < dealTime)
then screen { timer = timer screen + timePassed }
else screen
Expand All @@ -87,8 +92,9 @@ updateGame timePassed screen
| state screen == Start_Round =
if (street screen == Showdown)
then screen
{ state = Finish_Hand
, timer = 0
{ state = Finish_Hand
, timer = 0
, players = openHands $ players screen
}
else screen
{ state = Bet_Round
Expand All @@ -98,7 +104,8 @@ updateGame timePassed screen
, deck = snd $ snd boardDealResult
}
| state screen == Bet_Round =
if (checkSkipForActivePlayer $ players screen)
if (checkSkipForActivePlayer activePlayer maxBet $
countCanMovePlayers (players screen))
then screen { state = Next_Move }
else screen
{ state = case activePlayerType of
Expand Down Expand Up @@ -137,7 +144,7 @@ updateGame timePassed screen
then screen
{ state = Finish_Hand
, timer = 0
, players = applyMoveResults (players screen)
, players = openHands $ applyMoveResults (players screen)
}
else if (activePlayerPosition == lastPosition)
then if (checkReTrade (players screen) maxBet)
Expand All @@ -148,14 +155,14 @@ updateGame timePassed screen
, street = succ $ street screen
}
else screen
{ state = Bet_Round
, players = toggleNewActivePlayer (players screen) nextPosition
}
{ state = Bet_Round
, players = toggleNewActivePlayer (players screen) nextPosition
}
| state screen == Finish_Hand =
if (timer screen < showdownTime)
then screen { timer = timer screen + timePassed }
else screen
{ state = Dealing_Hand
{ state = Start_Hand
, timer = 0
, players = changePlayerPositions $ computeHandResults
(players screen) (board screen)
Expand Down
2 changes: 0 additions & 2 deletions src/Poker/Interface/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import Poker.Interface.Offsets
import Poker.Logic.Trading
import Poker.Logic.Types

import Debug.Trace

-------------------------------------------------------------------------------
-- * Handler functions
-------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/Poker/Interface/Loader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Poker.Logic.Types
loadedTableImages :: IO TableImages
loadedTableImages = do
Just imgBackground <- loadJuicyPNG "img/background.png"
Just imgWin <- loadJuicyPNG "img/text/win.png"
Just imgLoss <- loadJuicyPNG "img/text/loss.png"
Just imgTable <- loadJuicyPNG "img/table.png"
Just imgSeatBold <- loadJuicyPNG "img/seatbold.png"
Just imgSeatBoldActive <- loadJuicyPNG "img/seatbold active.png"
Expand All @@ -32,6 +34,8 @@ loadedTableImages = do
imgsChips <- loadChipLayout
return TableImages
{ background = imgBackground
, win = imgWin
, loss = imgLoss
, table = imgTable
, seatBold = imgSeatBold
, seatBoldActive = imgSeatBoldActive
Expand Down
4 changes: 4 additions & 0 deletions src/Poker/Interface/Offsets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ betWindowOffset = (buttonOffset * 1.5 - 33, -250)
-- | Offset for test in bet window.
betWindowTextOffset :: (Float, Float)
betWindowTextOffset = (-20, -6)

-- | Vertical offset for result message
resultMessageOffset :: Float
resultMessageOffset = 70
13 changes: 8 additions & 5 deletions src/Poker/Interface/Renderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import Poker.Interface.Offsets
import Poker.Logic.Trading
import Poker.Logic.Types

import Debug.Trace

-------------------------------------------------------------------------------
-- * Render functions
-------------------------------------------------------------------------------
Expand All @@ -23,10 +21,12 @@ drawTableScreen screen
| state screen == Dealing_Hand = pictures ([tableWithDealerChip] ++
map (\p -> playerOnSeatBold p) (players screen))
| state screen == Waiting_User_Input ||
state screen == Show_Click = pictures [tableWithDealerChip, potWithBoard, playersHands, playersBets,
state screen == Show_Click = pictures [tableWithDealerChip, potWithBoard, playersHands, playersWihtBets,
drawButtons possibleActions (button $ images screen, buttonClicked $ images screen)
(buttonTexts $ images screen) (pressed activePlayer), sliderImage, smallButtons, betWindowImage]
| otherwise = pictures [tableWithDealerChip, potWithBoard, playersHands, playersBets]
| state screen == Finish_Game = pictures [background $ images screen, table $ images screen,
playersWihtBets, resultMessage]
| otherwise = pictures [tableWithDealerChip, potWithBoard, playersHands, playersWihtBets]
where
chipImages = (chipLayout $ images screen)
playerOnSeatBold p = pictures [drawPlayerSeatBold p (case active p of
Expand All @@ -41,7 +41,7 @@ drawTableScreen screen
Bankrupted -> blank
Folded -> blank
_ -> pictures [drawPlayerHand p (deckLayout $ images screen)]) (players screen))
playersBets = pictures (map (\p -> pictures [playerOnSeatBold p, drawPlayerBet p chipImages]) (players screen))
playersWihtBets = pictures (map (\p -> pictures [playerOnSeatBold p, drawPlayerBet p chipImages]) (players screen))
activePlayer = getActivePlayer $ players screen
maxBet = countMaxBet $ players screen
possibleActions = getPossibleActions activePlayer maxBet
Expand All @@ -55,6 +55,9 @@ drawTableScreen screen
betWindowImage = case fst possibleActions /= All_In of
True -> drawBetWindow (currentValue $ sliderData screen) (betWindow $ images screen)
False -> blank
resultMessage = case checkWin (players screen) (hero screen) of
True -> translate 0 resultMessageOffset (win $ images screen)
False -> translate 0 resultMessageOffset (loss $ images screen)

-- | Draw player seatbold.
drawPlayerSeatBold :: Player -> Picture -> Picture
Expand Down
3 changes: 3 additions & 0 deletions src/Poker/Interface/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data TableScreen = TableScreen
{ state :: GameState -- ^ current game state
, timer :: Float -- ^ for detecting time
, players :: [Player] -- ^ info about every player
, hero :: String -- ^ name of hero
, street :: Street -- ^ current street
, handCount :: Int -- ^ current hand number
, dealer :: Seat -- ^ position of dealer
Expand All @@ -29,6 +30,8 @@ data TableScreen = TableScreen
-- | Contain all images relative to table game screen.
data TableImages = TableImages
{ background :: Picture
, win :: Picture
, loss :: Picture
, table :: Picture
, seatBold :: Picture
, seatBoldActive :: Picture
Expand Down
19 changes: 17 additions & 2 deletions src/Poker/Logic/Calculations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Data.List (sort)

import Poker.Logic.Types

import Debug.Trace
--import Debug.Trace

-------------------------------------------------------------------------------
-- * Functions to operate with cards
Expand Down Expand Up @@ -85,7 +85,8 @@ computeCombination :: Maybe (Card, Card) -> [Card] -> Combination
computeCombination handCards board = Combination
{ handRank = fst handRankComputations
, structure = fst $ snd handRankComputations
, kicker = snd $ snd handRankComputations }
, kicker = snd $ snd handRankComputations
}
where
handRankComputations = computeHandRank allCards
allCards = case handCards of
Expand Down Expand Up @@ -144,3 +145,17 @@ countRanks cards = foldl (\ranks card -> addRank ranks $ fromEnum (cardRank card
takeEqualBestN :: Int -> Int -> [Int] -> [Int]
takeEqualBestN n num list = snd . unzip . take n $ reverse
(filter (\x -> fst x == num) (zip list [0..12]))

-- | Convert combination list to bool list with marked top combinations.
-- Receive combination list zipped with bool list that indicates if
-- the combination require to participate in comparing.
markWinningCombinations :: [(Bool, Combination)] -> [Bool]
markWinningCombinations participateAndCombinations = bitWinners
where
filteredWithIndexes = map (\((_,c),i) -> (c,i)) $ filter (\pAc -> fst $ fst pAc)
(zip participateAndCombinations [0..length participateAndCombinations])
sorted = reverse $ sort filteredWithIndexes
winners = (head sorted:takeWhile (\(c, _) -> c == fst (head sorted)) (tail sorted))
bitWinners = foldl (\bitmap index ->
fst (splitAt index bitmap) ++ [True] ++ tail (snd $ splitAt index bitmap))
(replicate (length participateAndCombinations) False) (snd $ unzip winners)
15 changes: 11 additions & 4 deletions src/Poker/Logic/Dealer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,26 @@ dealBoard randomizer deck board street
-- * Operations with players
-------------------------------------------------------------------------------

-- | Take blind from player.
-- | Take blind from player and mark bankrupted players.
takeBlind :: Player -> Int -> Player
takeBlind player blind
| balance player == 0 = player
{ move = Move Bankrupted 0 }
| balance player <= blind = player
{ move = Move All_In_ed (balance player) }
| otherwise = player
{ move = Move Raised blind }
{ move = Move Waiting blind }

-- | Take blinds from players.
-- | Take blinds from players and mark bankrupted players.
takeBlinds :: [Player] -> Int -> [Player]
takeBlinds [] _ = []
takeBlinds (p:ps) bb =
let takeBB player blind = case position player of
SB -> takeBlind player (blind `div` 2)
BB -> takeBlind player blind
_ -> player
_ -> if (balance player == 0)
then player { move = Move Bankrupted 0 }
else player
in (takeBB p bb : takeBlinds ps bb)

-- | Hide hand depending on player type and settings.
Expand All @@ -86,6 +89,10 @@ hideHands players = map
AI -> player { hideHand = hideAIhand })
players

-- | Open all hands.
openHands :: [Player] -> [Player]
openHands players = map (\player -> player { hideHand = False }) players

-------------------------------------------------------------------------------
-- * Constants
-------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 74f72f0

Please sign in to comment.