<commit_before>require 'spec_helper'
require_relative '../corals/dominoes'

describe 'Dominoes' do

  describe 'Game' do

    it '1 table 4 players & 55 dominoes' do

      test :dominoes, then: {
        table: [],
        players: -> { expect(count).to eq 4 },
        dominoes: -> { expect(count).to eq 55 }
      }

    end

  end

  describe 'Start' do

    it 'empty table, each player with 10 dominoes' do

      test :dominoes,
        when: { on: :start },
        then: {
          table: [],
          players: -> { all? { |_, dominoes| expect(dominoes.count).to eq 10 }},
          dominoes: -> { expect(count).to eq 15 }
        }

    end

  end

  describe 'Turn' do

    it 'can play anything if table is empty' do

      test :dominoes,
        given: { players: { player: [[9,9]] } },
        when: { on: :turn },
        then: { domino: [9,9], players: { player: [] }}

    end

    it 'finds a domino to play' do

      test :dominoes,
        given: { table: [[9,9]], players: { player: [[0,0],[9,8],[8,8]] }},
        when: { on: :turn },
        then: { domino: [9,8], players: { player: [[0,0],[8,8]] }}

    end

    it 'finds nothing if cannot play' do

      test :dominoes,
        given: { table: [[9,9]], players: { player: [[0,0],[8,8]] }},
        when: { on: :turn },
        then: { domino: nil, players: { player: [[0,0],[8,8]] }}

    end

  end

  describe 'Play' do

    it 'the domino goes on the table' do

      test :dominoes,
        when: { on: :play, domino: [9,9] },
        then: { table: [[9,9]] }

    end

    it 'the head indicates preference' do

      test :dominoes,
        given: { table: [[9,9],[9,8],[8,7]] },
        when: { on: :play, domino: [9,7] },
        then: { table: [[7,9],[9,9],[9,8],[8,7]] }

      test :dominoes,
        given: { table: [[9,9],[9,8],[8,7]] },
        when: { on: :play, domino: [7,9] },
        then: { table: [[9,9],[9,8],[8,7],[7,9]] }

    end

    it 'the tail is an afterthought' do

      test :dominoes,
        given: { table: [[9,9]] },
        when: { on: :play, domino: [7,9] },
        then: { table: [[7,9],[9,9]] }

      test :dominoes,
        given: { table: [[9,9],[9,8]] },
        when: { on: :play, domino: [7,8] },
        then: { table: [[9,9],[9,8],[8,7]] }

    end

  end

  describe 'Controller' do

    it 'starts the game' do

      test :dominoes, then: { on: :start }

    end

    it 'player has the first turn' do

      test :dominoes,
        when: { on: :start },
        then: { on: :turn, player: :player }

    end

    it 'plays the domino' do

      test :dominoes,
        given: { players: { player:[:domino] } },
        when: { on: :turn, player: :player },
        then: { on: :play }

    end

    it 'knocks' do

      test :dominoes,
        when: { on: :turn, player: :player },
        then: { on: :knock, knocked: [:player] }

    end

    it 'finds next player after play' do

      test :dominoes,
        given: { players: { player: [:more_dominoes]}},
        when: { on: :play, domino: :domino },
        then: { on: :turn, player: :right }

    end

    it 'finds next player after knock' do

      test :dominoes,
        when: { on: :knock, player: :left },
        then: { on: :turn, player: :player }

    end

    it 'stops the game when stuck' do

      test :dominoes,
        given: { knocked: [:right, :front, :left, :player]},
        when: { on: :knock },
        then: { on: :stuck }

    end

    it 'calls the winner' do

      test :dominoes,
        when: { on: :play, domino: :domino },
        then: { on: :won }

    end

    it 'winner has the first turn'

  end

end<commit_msg>the end game<commit_after>require 'spec_helper'
require_relative '../corals/dominoes'

describe 'Dominoes' do

  describe 'Defaults' do

    it '1 table 4 players & 55 dominoes' do

      test :dominoes, then: {
        table: [],
        players: -> { expect(count).to eq 4 },
        dominoes: -> { expect(count).to eq 55 }
      }

    end

  end

  describe 'Start' do

    it 'empty table, each player with 10 dominoes' do

      test :dominoes,
        when: { on: :start },
        then: {
          table: [],
          players: -> { all? { |_, dominoes| expect(dominoes.count).to eq 10 }},
          dominoes: -> { expect(count).to eq 15 }
        }

    end

  end

  describe 'Turn' do

    it 'can play anything if table is empty' do

      test :dominoes,
        given: { players: { player: [[9,9]] } },
        when: { on: :turn },
        then: { domino: [9,9], players: { player: [] }}

    end

    it 'finds a domino to play' do

      test :dominoes,
        given: { table: [[9,9]], players: { player: [[0,0],[9,8],[8,8]] }},
        when: { on: :turn },
        then: { domino: [9,8], players: { player: [[0,0],[8,8]] }}

    end

    it 'finds nothing if cannot play' do

      test :dominoes,
        given: { table: [[9,9]], players: { player: [[0,0],[8,8]] }},
        when: { on: :turn },
        then: { domino: nil, players: { player: [[0,0],[8,8]] }}

    end

  end

  describe 'Play' do

    it 'the domino goes on the table' do

      test :dominoes,
        when: { on: :play, domino: [9,9] },
        then: { table: [[9,9]] }

    end

    it 'the head indicates preference' do

      test :dominoes,
        given: { table: [[9,9],[9,8],[8,7]] },
        when: { on: :play, domino: [9,7] },
        then: { table: [[7,9],[9,9],[9,8],[8,7]] }

      test :dominoes,
        given: { table: [[9,9],[9,8],[8,7]] },
        when: { on: :play, domino: [7,9] },
        then: { table: [[9,9],[9,8],[8,7],[7,9]] }

    end

    it 'the tail is an afterthought' do

      test :dominoes,
        given: { table: [[9,9]] },
        when: { on: :play, domino: [7,9] },
        then: { table: [[7,9],[9,9]] }

      test :dominoes,
        given: { table: [[9,9],[9,8]] },
        when: { on: :play, domino: [7,8] },
        then: { table: [[9,9],[9,8],[8,7]] }

    end

  end

  describe 'Controller' do

    it 'starts the game' do

      test :dominoes, then: { on: :start }

    end

    it 'player has the first turn' do

      test :dominoes,
        when: { on: :start },
        then: { on: :turn, player: :player }

    end

    it 'plays the domino' do

      test :dominoes,
        given: { players: { player:[:domino] } },
        when: { on: :turn, player: :player },
        then: { on: :play }

    end

    it 'knocks' do

      test :dominoes,
        when: { on: :turn, player: :player },
        then: { on: :knock, knocked: [:player] }

    end

    it 'finds next player after play' do

      test :dominoes,
        given: { players: { player: [:more_dominoes]}},
        when: { on: :play, domino: :domino },
        then: { on: :turn, player: :right }

    end

    it 'finds next player after knock' do

      test :dominoes,
        when: { on: :knock, player: :left },
        then: { on: :turn, player: :player }

    end

    it 'stops the game when stuck' do

      test :dominoes,
        given: { knocked: [:right, :front, :left, :player]},
        when: { on: :knock },
        then: { on: :stuck }

    end

    it 'calls the winner' do

      test :dominoes,
        when: { on: :play, domino: :domino },
        then: { on: :won }

    end

  end

  let(:game) {{}}

  it 'plays a game' do
     game = resolve game, [:dominoes] until game[:winner]
  end

end
{'fraction_non_alphanumeric': 0.1744028230184582, 'fraction_numerical': 0.026330076004343107, 'mean_word_length': 1.9452438049560352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2116371', 'n_tokens_mistral': 2812, 'n_tokens_neox': 2618, 'n_words': 786}