Skip to content

Commit c73a43c

Browse files
committed
cleanup warnings
1 parent e0f8043 commit c73a43c

25 files changed

Lines changed: 370 additions & 231 deletions

apps/lora/.formatter.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[
2-
import_deps: [:ecto, :ecto_sql],
32
subdirectories: ["priv/*/migrations"],
43
plugins: [Phoenix.LiveView.HTMLFormatter],
54
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]

apps/lora/lib/lora/contract.ex

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@ defmodule Lora.Contract do
33
Defines the seven contracts of the Lora card game and their scoring rules.
44
"""
55

6-
@type t :: :minimum | :maximum | :queens | :hearts | :jack_of_clubs | :king_hearts_last_trick | :lora
6+
@type t ::
7+
:minimum
8+
| :maximum
9+
| :queens
10+
| :hearts
11+
| :jack_of_clubs
12+
| :king_hearts_last_trick
13+
| :lora
714

8-
@contracts [:minimum, :maximum, :queens, :hearts, :jack_of_clubs, :king_hearts_last_trick, :lora]
15+
@contracts [
16+
:minimum,
17+
:maximum,
18+
:queens,
19+
:hearts,
20+
:jack_of_clubs,
21+
:king_hearts_last_trick,
22+
:lora
23+
]
924

1025
@doc """
1126
Returns all available contracts in their fixed order.
@@ -40,10 +55,19 @@ defmodule Lora.Contract do
4055
def description(:minimum), do: "Plus one point per trick taken"
4156
def description(:maximum), do: "Minus one point per trick taken"
4257
def description(:queens), do: "Plus two points per queen taken"
43-
def description(:hearts), do: "Plus one point per heart taken; minus eight if one player takes all hearts"
58+
59+
def description(:hearts),
60+
do: "Plus one point per heart taken; minus eight if one player takes all hearts"
61+
4462
def description(:jack_of_clubs), do: "Plus eight points to the player who takes it"
45-
def description(:king_hearts_last_trick), do: "Plus four points each for King of Hearts and Last Trick; plus eight if captured in the same trick"
46-
def description(:lora), do: "Minus eight to the first player who empties hand; all others receive plus one point per remaining card"
63+
64+
def description(:king_hearts_last_trick),
65+
do:
66+
"Plus four points each for King of Hearts and Last Trick; plus eight if captured in the same trick"
67+
68+
def description(:lora),
69+
do:
70+
"Minus eight to the first player who empties hand; all others receive plus one point per remaining card"
4771

4872
@doc """
4973
Returns whether the contract is a trick-taking contract or Lora.

apps/lora/lib/lora/contracts/hearts.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Lora.Contracts.Hearts do
77

88
@behaviour Lora.Contracts.ContractBehaviour
99

10-
alias Lora.{Game, Score}
10+
alias Lora.Score
1111
alias Lora.Contracts.TrickTaking
1212

1313
@impl true

apps/lora/lib/lora/contracts/jack_of_clubs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Lora.Contracts.JackOfClubs do
66

77
@behaviour Lora.Contracts.ContractBehaviour
88

9-
alias Lora.{Game, Score}
9+
alias Lora.Score
1010
alias Lora.Contracts.TrickTaking
1111

1212
@impl true

apps/lora/lib/lora/contracts/king_hearts_last_trick.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Lora.Contracts.KingHeartsLastTrick do
77

88
@behaviour Lora.Contracts.ContractBehaviour
99

10-
alias Lora.{Game, Score}
10+
alias Lora.Score
1111
alias Lora.Contracts.TrickTaking
1212

1313
@impl true

apps/lora/lib/lora/contracts/lora.ex

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule Lora.Contracts.Lora do
1212
@impl true
1313
def is_legal_move?(state, seat, {suit, rank}) do
1414
layout = state.lora_layout
15-
hand = state.hands[seat]
15+
_hand = state.hands[seat]
1616

1717
# If this is the first card played in Lora, any card is legal
1818
if Enum.all?(layout, fn {_, cards} -> cards == [] end) do
@@ -32,8 +32,10 @@ defmodule Lora.Contracts.Lora do
3232
|> Enum.find(fn _ -> true end)
3333

3434
case any_laid_card do
35-
nil -> true # No cards played yet
36-
{_, first_rank} -> rank == first_rank # Must match the first played card's rank
35+
# No cards played yet
36+
nil -> true
37+
# Must match the first played card's rank
38+
{_, first_rank} -> rank == first_rank
3739
end
3840

3941
# Cards of this suit already played, card must be the next in sequence
@@ -59,11 +61,7 @@ defmodule Lora.Contracts.Lora do
5961
{next_player, can_anyone_play} = find_next_player_who_can_play(state, hands, seat)
6062

6163
if can_anyone_play do
62-
{:ok, %{state |
63-
hands: hands,
64-
lora_layout: lora_layout,
65-
current_player: next_player
66-
}}
64+
{:ok, %{state | hands: hands, lora_layout: lora_layout, current_player: next_player}}
6765
else
6866
# No one can play, the deal is over
6967
deal_over_state = handle_lora_winner(state, hands, seat)
@@ -156,20 +154,17 @@ defmodule Lora.Contracts.Lora do
156154

157155
# Check if the game is over
158156
if Game.game_over?(state) do
159-
%{state |
160-
hands: hands,
161-
scores: updated_scores,
162-
phase: :finished
163-
}
157+
%{state | hands: hands, scores: updated_scores, phase: :finished}
164158
else
165159
# Move to the next contract or dealer
166160
{next_dealer, next_contract} = Game.next_dealer_and_contract(state)
167161

168162
# Deal the next contract
169-
Game.deal_new_contract(%{state |
170-
dealer_seat: next_dealer,
171-
contract_index: next_contract,
172-
scores: updated_scores
163+
Game.deal_new_contract(%{
164+
state
165+
| dealer_seat: next_dealer,
166+
contract_index: next_contract,
167+
scores: updated_scores
173168
})
174169
end
175170
end

apps/lora/lib/lora/contracts/maximum.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Lora.Contracts.Maximum do
66

77
@behaviour Lora.Contracts.ContractBehaviour
88

9-
alias Lora.{Game, Score}
9+
alias Lora.Score
1010
alias Lora.Contracts.TrickTaking
1111

1212
@impl true

apps/lora/lib/lora/contracts/minimum.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Lora.Contracts.Minimum do
66

77
@behaviour Lora.Contracts.ContractBehaviour
88

9-
alias Lora.{Game, Score}
9+
alias Lora.Score
1010
alias Lora.Contracts.TrickTaking
1111

1212
@impl true

apps/lora/lib/lora/contracts/queens.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Lora.Contracts.Queens do
66

77
@behaviour Lora.Contracts.ContractBehaviour
88

9-
alias Lora.{Game, Score}
9+
alias Lora.Score
1010
alias Lora.Contracts.TrickTaking
1111

1212
@impl true

apps/lora/lib/lora/contracts/trick_taking.ex

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ defmodule Lora.Contracts.TrickTaking do
1414

1515
case state.trick do
1616
# First card in trick can be anything
17-
[] -> true
17+
[] ->
18+
true
1819

1920
# Otherwise must follow suit if possible
2021
[{_, {led_suit, _}} | _] ->
@@ -40,10 +41,11 @@ defmodule Lora.Contracts.TrickTaking do
4041
winner_seat = Deck.trick_winner(updated_trick)
4142

4243
# Add the cards from the trick to the winner's taken pile
43-
taken = Map.update!(state.taken, winner_seat, fn taken_cards ->
44-
trick_cards = Enum.map(updated_trick, fn {_seat, card} -> card end)
45-
taken_cards ++ [trick_cards]
46-
end)
44+
taken =
45+
Map.update!(state.taken, winner_seat, fn taken_cards ->
46+
trick_cards = Enum.map(updated_trick, fn {_seat, card} -> card end)
47+
taken_cards ++ [trick_cards]
48+
end)
4749

4850
# Check if the deal is over (all cards played)
4951
if Enum.all?(hands, fn {_seat, hand} -> hand == [] end) do
@@ -52,12 +54,7 @@ defmodule Lora.Contracts.TrickTaking do
5254
{:ok, deal_over_state}
5355
else
5456
# Continue with the next trick, winner leads
55-
{:ok, %{state |
56-
hands: hands,
57-
trick: [],
58-
taken: taken,
59-
current_player: winner_seat
60-
}}
57+
{:ok, %{state | hands: hands, trick: [], taken: taken, current_player: winner_seat}}
6158
end
6259
else
6360
# Continue with the next player
@@ -81,21 +78,17 @@ defmodule Lora.Contracts.TrickTaking do
8178

8279
# Check if the game is over
8380
if Game.game_over?(state) do
84-
%{state |
85-
hands: hands,
86-
taken: taken,
87-
scores: updated_scores,
88-
phase: :finished
89-
}
81+
%{state | hands: hands, taken: taken, scores: updated_scores, phase: :finished}
9082
else
9183
# Move to the next contract or dealer
9284
{next_dealer, next_contract} = Game.next_dealer_and_contract(state)
9385

9486
# Deal the next contract
95-
Game.deal_new_contract(%{state |
96-
dealer_seat: next_dealer,
97-
contract_index: next_contract,
98-
scores: updated_scores
87+
Game.deal_new_contract(%{
88+
state
89+
| dealer_seat: next_dealer,
90+
contract_index: next_contract,
91+
scores: updated_scores
9992
})
10093
end
10194
end

0 commit comments

Comments
 (0)