Packages
Creates a tally struct for the Game of Islands. Also displays the summary of a Game of Islands.
Current section
30 Versions
Jump to
Current section
30 Versions
Compare versions
3
files changed
+8
additions
-34
deletions
| @@ -40,11 +40,6 @@ | |
| 40 40 | {<<"optional">>,false}, |
| 41 41 | {<<"repository">>,<<"hexpm">>}, |
| 42 42 | {<<"requirement">>,<<"~> 0.1">>}], |
| 43 | - [{<<"app">>,<<"islands_player">>}, |
| 44 | - {<<"name">>,<<"islands_player">>}, |
| 45 | - {<<"optional">>,false}, |
| 46 | - {<<"repository">>,<<"hexpm">>}, |
| 47 | - {<<"requirement">>,<<"~> 0.1">>}], |
| 48 43 | [{<<"app">>,<<"islands_player_id">>}, |
| 49 44 | {<<"name">>,<<"islands_player_id">>}, |
| 50 45 | {<<"optional">>,false}, |
| @@ -70,4 +65,4 @@ | |
| 70 65 | {<<"optional">>,false}, |
| 71 66 | {<<"repository">>,<<"hexpm">>}, |
| 72 67 | {<<"requirement">>,<<"~> 0.1">>}]]}. |
| 73 | - {<<"version">>,<<"0.1.0">>}. |
| 68 | + {<<"version">>,<<"0.1.1">>}. |
| @@ -17,7 +17,6 @@ defmodule Islands.Tally do | |
| 17 17 | Board, |
| 18 18 | Game, |
| 19 19 | Guesses, |
| 20 | - Player, |
| 21 20 | PlayerID, |
| 22 21 | Request, |
| 23 22 | Response, |
| @@ -25,14 +24,14 @@ defmodule Islands.Tally do | |
| 25 24 | State |
| 26 25 | } |
| 27 26 | |
| 27 | + @player_ids [:player1, :player2] |
| 28 | + |
| 28 29 | @derive [Poison.Encoder] |
| 29 30 | @derive Jason.Encoder |
| 30 31 | @enforce_keys [ |
| 31 32 | :game_state, |
| 32 33 | :player1_state, |
| 33 | - :player1, |
| 34 34 | :player2_state, |
| 35 | - :player2, |
| 36 35 | :request, |
| 37 36 | :response, |
| 38 37 | :board, |
| @@ -43,9 +42,7 @@ defmodule Islands.Tally do | |
| 43 42 | defstruct [ |
| 44 43 | :game_state, |
| 45 44 | :player1_state, |
| 46 | - :player1, |
| 47 45 | :player2_state, |
| 48 | - :player2, |
| 49 46 | :request, |
| 50 47 | :response, |
| 51 48 | :board, |
| @@ -57,9 +54,7 @@ defmodule Islands.Tally do | |
| 57 54 | @type t :: %Tally{ |
| 58 55 | game_state: State.game_state(), |
| 59 56 | player1_state: State.player_state(), |
| 60 | - player1: Player.t(), |
| 61 57 | player2_state: State.player_state(), |
| 62 | - player2: Player.t(), |
| 63 58 | request: Request.t(), |
| 64 59 | response: Response.t(), |
| 65 60 | board: Board.t(), |
| @@ -68,35 +63,20 @@ defmodule Islands.Tally do | |
| 68 63 | guesses_score: Score.t() |
| 69 64 | } |
| 70 65 | |
| 71 | - @player_ids [:player1, :player2] |
| 72 | - |
| 73 66 | @spec new(Game.t(), PlayerID.t()) :: t | {:error, atom} |
| 74 67 | def new(%Game{} = game, player_id) when player_id in @player_ids do |
| 75 | - player = game[player_id] |
| 76 | - opponent = game[Game.opponent_id(player_id)] |
| 77 | - |
| 78 68 | %Tally{ |
| 79 69 | game_state: game.state.game_state, |
| 80 70 | player1_state: game.state.player1_state, |
| 81 | - player1: game.player1, |
| 82 71 | player2_state: game.state.player2_state, |
| 83 | - player2: game.player2, |
| 84 72 | request: game.request, |
| 85 73 | response: game.response, |
| 86 | - board: player.board, |
| 87 | - board_score: Score.new(player.board), |
| 88 | - guesses: player.guesses, |
| 89 | - guesses_score: Score.new(opponent.board) |
| 74 | + board: game[player_id].board, |
| 75 | + board_score: Score.board_score(game, player_id), |
| 76 | + guesses: game[player_id].guesses, |
| 77 | + guesses_score: Score.guesses_score(game, player_id) |
| 90 78 | } |
| 91 79 | end |
| 92 80 | |
| 93 81 | def new(_game, _player_id), do: {:error, :invalid_tally_args} |
| 94 | - |
| 95 | - @spec player(t, PlayerID.t()) :: Player.t() |
| 96 | - def player(%Tally{} = tally, :player1), do: tally.player1 |
| 97 | - def player(%Tally{} = tally, :player2), do: tally.player2 |
| 98 | - |
| 99 | - @spec opponent(t, PlayerID.t()) :: Player.t() |
| 100 | - def opponent(%Tally{} = tally, :player1), do: tally.player2 |
| 101 | - def opponent(%Tally{} = tally, :player2), do: tally.player1 |
| 102 82 | end |
| @@ -4,7 +4,7 @@ defmodule Islands.Tally.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :islands_tally, |
| 7 | - version: "0.1.0", |
| 7 | + version: "0.1.1", |
| 8 8 | elixir: "~> 1.7", |
| 9 9 | start_permanent: Mix.env() == :prod, |
| 10 10 | name: "Islands Tally", |
| @@ -52,7 +52,6 @@ defmodule Islands.Tally.MixProject do | |
| 52 52 | {:islands_board, "~> 0.1"}, |
| 53 53 | {:islands_game, "~> 0.1"}, |
| 54 54 | {:islands_guesses, "~> 0.1"}, |
| 55 | - {:islands_player, "~> 0.1"}, |
| 56 55 | {:islands_player_id, "~> 0.1"}, |
| 57 56 | {:islands_request, "~> 0.1"}, |
| 58 57 | {:islands_response, "~> 0.1"}, |