Skip to content

Commit 874188e

Browse files
chore(format): apply formatter (#69)
1 parent af7c7f1 commit 874188e

File tree

12 files changed

+204
-183
lines changed

12 files changed

+204
-183
lines changed

src/main/kotlin/hwr/oop/projects/peakpoker/core/card/CommunityCards.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ class CommunityCards(
1616
/**
1717
* Exception thrown when the number of community cards is invalid
1818
*/
19-
class InvalidCardConfigurationException(message: String) : IllegalStateException(message)
19+
class InvalidCardConfigurationException(message: String) :
20+
IllegalStateException(message)
2021

2122
/**
2223
* Exception thrown when attempting to deal community cards in an invalid round phase
2324
*/
24-
class InvalidDealPhaseException(message: String) : IllegalStateException(message)
25+
class InvalidDealPhaseException(message: String) :
26+
IllegalStateException(message)
2527

2628
init {
2729
if (cards.isNotEmpty() && cards.size !in listOf(3, 4, 5)) {

src/main/kotlin/hwr/oop/projects/peakpoker/core/card/HoleCards.kt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@ import kotlinx.serialization.Transient
66

77
@Serializable
88
class HoleCards(
9-
val cards: List<Card>,
10-
@Transient val player: PokerPlayer? = null,
9+
val cards: List<Card>,
10+
@Transient val player: PokerPlayer? = null,
1111
) : Iterable<Card> by cards {
12-
/**
13-
* Exception thrown when duplicate cards are found in the hole cards
14-
*/
15-
class DuplicateCardException(message: String) : IllegalStateException(message)
12+
/**
13+
* Exception thrown when duplicate cards are found in the hole cards
14+
*/
15+
class DuplicateCardException(message: String) : IllegalStateException(message)
1616

17-
/**
18-
* Exception thrown when the number of hole cards is invalid
19-
*/
20-
class InvalidCardConfigurationException(message: String) : IllegalStateException(message)
17+
/**
18+
* Exception thrown when the number of hole cards is invalid
19+
*/
20+
class InvalidCardConfigurationException(message: String) :
21+
IllegalStateException(message)
2122

22-
init {
23-
if (cards.isNotEmpty() && cards.size != 2) {
24-
throw InvalidCardConfigurationException("Hole cards must be empty or contain exactly two cards.")
25-
}
26-
if (cards.distinct().size != cards.size) {
27-
throw DuplicateCardException("Hole cards must not contain duplicates.")
28-
}
23+
init {
24+
if (cards.isNotEmpty() && cards.size != 2) {
25+
throw InvalidCardConfigurationException("Hole cards must be empty or contain exactly two cards.")
2926
}
27+
if (cards.distinct().size != cards.size) {
28+
throw DuplicateCardException("Hole cards must not contain duplicates.")
29+
}
30+
}
3031
}

src/main/kotlin/hwr/oop/projects/peakpoker/core/card/Rank.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import kotlinx.serialization.Serializable
44

55
@Serializable
66
enum class Rank(
7-
val value: Int,
7+
val value: Int,
88
) {
9-
TWO(1),
10-
THREE(2),
11-
FOUR(3),
12-
FIVE(4),
13-
SIX(5),
14-
SEVEN(6),
15-
EIGHT(7),
16-
NINE(8),
17-
TEN(9),
18-
JACK(10),
19-
QUEEN(11),
20-
KING(12),
21-
ACE(13)
9+
TWO(1),
10+
THREE(2),
11+
FOUR(3),
12+
FIVE(4),
13+
SIX(5),
14+
SEVEN(6),
15+
EIGHT(7),
16+
NINE(8),
17+
TEN(9),
18+
JACK(10),
19+
QUEEN(11),
20+
KING(12),
21+
ACE(13)
2222
}

src/main/kotlin/hwr/oop/projects/peakpoker/core/card/Suit.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import kotlinx.serialization.Serializable
44

55
@Serializable
66
enum class Suit {
7-
HEARTS, DIAMONDS, CLUBS, SPADES
7+
HEARTS, DIAMONDS, CLUBS, SPADES
88
}

src/main/kotlin/hwr/oop/projects/peakpoker/core/deck/Deck.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Deck() {
1111
/**
1212
* Thrown when trying to draw more cards than are available in the deck
1313
*/
14-
class InsufficientCardsException(message: String) : IllegalStateException(message)
14+
class InsufficientCardsException(message: String) :
15+
IllegalStateException(message)
1516

1617
// Create a list of all possible cards and shuffle it right away
1718
@Transient

src/main/kotlin/hwr/oop/projects/peakpoker/core/game/PokerGame.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ class PokerGame(
1313
/**
1414
* Exception thrown when duplicate player names are found
1515
*/
16-
class DuplicatePlayerException(message: String) : IllegalStateException(message)
16+
class DuplicatePlayerException(message: String) :
17+
IllegalStateException(message)
1718

1819
/**
1920
* Exception thrown when blind configuration is invalid
2021
*/
21-
class InvalidBlindConfigurationException(message: String) : IllegalStateException(message)
22+
class InvalidBlindConfigurationException(message: String) :
23+
IllegalStateException(message)
2224

2325
/**
2426
* Exception thrown when there are not enough players
2527
*/
26-
class MinimumPlayersException(message: String) : IllegalStateException(message)
28+
class MinimumPlayersException(message: String) :
29+
IllegalStateException(message)
2730

2831
/**
2932
* Exception thrown when trying to access a round when none is active

src/main/kotlin/hwr/oop/projects/peakpoker/core/game/PokerRound.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,44 @@ class PokerRound(
2020
/**
2121
* Exception thrown when a player attempts a betting action without sufficient chips
2222
*/
23-
class InsufficientChipsForBettingException(message: String) : IllegalStateException(message)
23+
class InsufficientChipsForBettingException(message: String) :
24+
IllegalStateException(message)
2425

2526
/**
2627
* Thrown when an action is attempted on a player in an invalid state
2728
*/
28-
class InvalidPlayerStateException(message: String) : IllegalStateException(message)
29+
class InvalidPlayerStateException(message: String) :
30+
IllegalStateException(message)
2931

3032
/**
3133
* Exception thrown when a bet amount violates poker betting rules
3234
*/
33-
class InvalidBetAmountException(message: String) : IllegalStateException(message)
35+
class InvalidBetAmountException(message: String) :
36+
IllegalStateException(message)
3437

3538
/**
3639
* Exception thrown when a player attempts an invalid call action
3740
*/
38-
class InvalidCallActionException(message: String) : IllegalStateException(message)
41+
class InvalidCallActionException(message: String) :
42+
IllegalStateException(message)
3943

4044
/**
4145
* Exception thrown when a player attempts an invalid check action
4246
*/
43-
class InvalidCheckActionException(message: String) : IllegalStateException(message)
47+
class InvalidCheckActionException(message: String) :
48+
IllegalStateException(message)
4449

4550
/**
4651
* Exception thrown when a player with a specified name is not found in the game
4752
*/
48-
class PlayerNotFoundException(message: String) : IllegalStateException(message)
53+
class PlayerNotFoundException(message: String) :
54+
IllegalStateException(message)
4955

5056
/**
5157
* Exception thrown when an invalid operation is attempted for the current round phase
5258
*/
53-
class IllegalRoundPhaseException(message: String) : IllegalStateException(message)
59+
class IllegalRoundPhaseException(message: String) :
60+
IllegalStateException(message)
5461

5562
@Transient
5663
private var onRoundComplete: () -> Unit =

src/main/kotlin/hwr/oop/projects/peakpoker/core/hand/HandEvaluator.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ class HandEvaluator(
1313
/**
1414
* Exception thrown when an empty player list is provided
1515
*/
16-
class EmptyPlayerListEvaluationException(message: String) : IllegalArgumentException(message)
16+
class EmptyPlayerListEvaluationException(message: String) :
17+
IllegalArgumentException(message)
1718

1819
/**
1920
* Exception thrown when an invalid number of cards is found
2021
*/
21-
class InvalidCardCountException(message: String) : IllegalArgumentException(message)
22+
class InvalidCardCountException(message: String) :
23+
IllegalArgumentException(message)
2224

2325
/**
2426
* Exception thrown when no valid hand can be found
2527
*/
26-
class NoValidHandFoundException(message: String) : IllegalStateException(message)
28+
class NoValidHandFoundException(message: String) :
29+
IllegalStateException(message)
2730

2831
/**
2932
* Determines all players with the highest hand among a list of players.

src/main/kotlin/hwr/oop/projects/peakpoker/core/player/PokerPlayer.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ class PokerPlayer(
1111
/**
1212
* Exception thrown when attempting to create a player with negative chips balance
1313
*/
14-
class InvalidInitialChipsBalanceException(message: String) : IllegalStateException(message)
14+
class InvalidInitialChipsBalanceException(message: String) :
15+
IllegalStateException(message)
1516

1617
/**
1718
* Exception thrown when a player name is invalid
1819
*/
19-
class InvalidPlayerNameException(message: String) : IllegalStateException(message)
20+
class InvalidPlayerNameException(message: String) :
21+
IllegalStateException(message)
2022

2123
/**
2224
* Exception thrown when performing an invalid betting operation
2325
*/
24-
class InvalidBetOperationException(message: String) : IllegalStateException(message)
26+
class InvalidBetOperationException(message: String) :
27+
IllegalStateException(message)
2528

2629

2730
init {

src/main/kotlin/hwr/oop/projects/peakpoker/core/pot/PokerPots.kt

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,83 @@ import kotlinx.serialization.Serializable
66

77
@Serializable
88
class PokerPots(
9-
private val players: List<PokerPlayer>,
10-
private val communityCards: CommunityCards,
11-
val pots: MutableList<Pot> =
12-
mutableListOf(
13-
Pot(
14-
eligiblePlayers = players.toSet(),
15-
communityCards = communityCards
16-
)
17-
),
9+
private val players: List<PokerPlayer>,
10+
private val communityCards: CommunityCards,
11+
val pots: MutableList<Pot> =
12+
mutableListOf(
13+
Pot(
14+
eligiblePlayers = players.toSet(),
15+
communityCards = communityCards
16+
)
17+
),
1818
) : Iterable<Pot> by pots {
19-
private val mainPot: Pot get() = pots.first()
19+
private val mainPot: Pot get() = pots.first()
2020

21-
fun addChipsToCurrentPot(chips: Int) {
22-
mainPot.addChips(chips)
23-
}
24-
25-
/**
26-
* Creates a side pot when a player goes all-in.
27-
*
28-
* This method:
29-
* 1. Calculates excess chips from other players (amounts above what the all-in player could match)
30-
* 2. Reduces those players' bets to match the all-in amount
31-
* 3. Moves excess chips from the main pot to a new side pot
32-
* 4. Makes the all-in player ineligible for the side pot
33-
*
34-
* @param allInPlayer The player who has gone all-in
35-
*/
36-
fun createSidePotIfNeeded(allInPlayer: PokerPlayer) {
37-
val excessAmount = calculateExcessAmount(allInPlayer)
21+
fun addChipsToCurrentPot(chips: Int) {
22+
mainPot.addChips(chips)
23+
}
3824

39-
// If no excess chips, no need for a side pot
40-
if (excessAmount <= 0) return
25+
/**
26+
* Creates a side pot when a player goes all-in.
27+
*
28+
* This method:
29+
* 1. Calculates excess chips from other players (amounts above what the all-in player could match)
30+
* 2. Reduces those players' bets to match the all-in amount
31+
* 3. Moves excess chips from the main pot to a new side pot
32+
* 4. Makes the all-in player ineligible for the side pot
33+
*
34+
* @param allInPlayer The player who has gone all-in
35+
*/
36+
fun createSidePotIfNeeded(allInPlayer: PokerPlayer) {
37+
val excessAmount = calculateExcessAmount(allInPlayer)
4138

42-
// If there are excess chips, move them to a side pot
39+
// If no excess chips, no need for a side pot
40+
if (excessAmount <= 0) return
4341

44-
// Reduce the main pot by the excess amount
45-
mainPot.removeChips(excessAmount)
42+
// If there are excess chips, move them to a side pot
4643

47-
// Create a side pot with eligible players (everyone but the all-in player)
48-
val eligiblePlayers =
49-
mainPot.eligiblePlayers.filter { it != allInPlayer }.toSet()
50-
pots.add(
51-
Pot(
52-
eligiblePlayers = eligiblePlayers,
53-
communityCards = communityCards,
54-
amount = excessAmount
55-
)
56-
)
57-
}
44+
// Reduce the main pot by the excess amount
45+
mainPot.removeChips(excessAmount)
5846

59-
/**
60-
* Calculates the excess amount of chips that should be moved to a side pot when a player goes all-in.
61-
*
62-
* This method:
63-
* 1. Determines the total amount the all-in player can bet (current bet and remaining chips)
64-
* 2. Identifies players who have bet more than this amount
65-
* 3. Calculates the total excess chips from these players
66-
* 4. Adjusts these players' bets to match the all-in amount
67-
*
68-
* @param allInPlayer The player who has gone all-in
69-
* @return The total excess amount that should be moved to a side pot
70-
*/
71-
private fun calculateExcessAmount(allInPlayer: PokerPlayer): Int {
72-
// Get all-in amount (player's bet and remaining chips)
73-
val allInTotal = allInPlayer.bet() + allInPlayer.chips()
47+
// Create a side pot with eligible players (everyone but the all-in player)
48+
val eligiblePlayers =
49+
mainPot.eligiblePlayers.filter { it != allInPlayer }.toSet()
50+
pots.add(
51+
Pot(
52+
eligiblePlayers = eligiblePlayers,
53+
communityCards = communityCards,
54+
amount = excessAmount
55+
)
56+
)
57+
}
7458

75-
// Calculate excess chips from other players
76-
var excessAmount = 0
77-
players.forEach { player ->
78-
if (!player.isFolded() && player != allInPlayer && player.bet() > allInTotal) {
79-
val excess = player.bet() - allInTotal
80-
excessAmount += excess
81-
// Adjust player's bet to match all-in
82-
player.setBetAmount(allInTotal)
83-
}
84-
}
59+
/**
60+
* Calculates the excess amount of chips that should be moved to a side pot when a player goes all-in.
61+
*
62+
* This method:
63+
* 1. Determines the total amount the all-in player can bet (current bet and remaining chips)
64+
* 2. Identifies players who have bet more than this amount
65+
* 3. Calculates the total excess chips from these players
66+
* 4. Adjusts these players' bets to match the all-in amount
67+
*
68+
* @param allInPlayer The player who has gone all-in
69+
* @return The total excess amount that should be moved to a side pot
70+
*/
71+
private fun calculateExcessAmount(allInPlayer: PokerPlayer): Int {
72+
// Get all-in amount (player's bet and remaining chips)
73+
val allInTotal = allInPlayer.bet() + allInPlayer.chips()
8574

86-
return excessAmount
75+
// Calculate excess chips from other players
76+
var excessAmount = 0
77+
players.forEach { player ->
78+
if (!player.isFolded() && player != allInPlayer && player.bet() > allInTotal) {
79+
val excess = player.bet() - allInTotal
80+
excessAmount += excess
81+
// Adjust player's bet to match all-in
82+
player.setBetAmount(allInTotal)
83+
}
8784
}
85+
86+
return excessAmount
87+
}
8888
}

0 commit comments

Comments
 (0)