> For the complete documentation index, see [llms.txt](https://kashiwara.gitbook.io/rubydesurufurusukuratchibe/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kashiwara.gitbook.io/rubydesurufurusukuratchibe/rifakutaringu/playerclassno.md).

# PlayerClassの実装

PlayerClassを実装します。

### プレイヤーに関する動作を一まとめにする

先ほど実装したvalidate\_positionを使い、以下のplayer.rbを作成していきましょう。

```ruby
# frozen_string_literal: true

require_relative "tic_tac_toe_validator"

# Playerの打ち手を管理をする
class Player

  attr_reader :piece

  def initialize(piece:)
    @piece = piece
  end

  # 概要: コマを配置する行と列の値をコンソールから受け取り返却する
  # 引数: なし
  # 戻り値: 入力された行と列の情報を配列に格納して返却する => ["1", "1"]
  def gets_piece_location
    print "行を入力してください:"
    user_input_row = gets

    print "列を入力してください:"
    user_input_col = gets

    TicTacToeValidator.validate_input_value!(user_input_row, user_input_col)

    [user_input_row.to_i, user_input_col.to_i]
  end
end

```

入力値も検証できていい感じです。

{% hint style="info" %}
**課題コーナー**

player\_test.rbを作成しテストを実装する
{% endhint %}

### テスト実装

元あったテストファイルからPlayerクラスのテストを抽出して新たにplayer\_test.rbを作成します。

参考コードは以下のURLから参照してください。

{% embed url="<https://github.com/Kashiwara0205/ruby-tic-tac-toe/blob/master/ch4/code/test/player_test.rb>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://kashiwara.gitbook.io/rubydesurufurusukuratchibe/rifakutaringu/playerclassno.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
