> 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/zui-zhong-zhang-ji-neng-zhui-jia/gamemanagerfactoryclassno.md).

# GameManagerFactoryClassの修正

### constにユニーク値を追加

4章で追加したconstファイルにプレイヤーのユニーク値を追加します。

```ruby
RANDOM_COM_PLAYER = 0
OEDERLY_COM_PLAYER = 1
USER_PLAYER = 2
```

### GameManagerFactoryClassの修正する

GameManagerFactoryClassのcreateメソッドにてplayer\_nameを受け取れるようにします。

player\_nameに応じてPlayerクラスを決定しGameManagerに渡します。

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

GameManagerFactoryClassを改修する
{% endhint %}

私は、以下のように実装しました

```ruby
# frozen_string_literal: true

require_relative "const"
require_relative "game_manager"
require_relative "players/user_player"
require_relative "players/ordely_com_player"
require_relative "players/random_com_player"
require_relative "board"

# ゲームマネージャークラスを作成する
class GameManagerFactory
  class << self
    # 概要: GameManagerクラスを作成し返却する
    # 引数: player1_name: plyaer1の名前。数値
    #      player2_name: plyaer2の名前。数値
    # 戻り値: GameManegerクラスのインスタンス
    def create(player1_name, player2_name)
      board = Board.new([
                          [OPEN_SLOT, OPEN_SLOT, OPEN_SLOT],
                          [OPEN_SLOT, OPEN_SLOT, OPEN_SLOT],
                          [OPEN_SLOT, OPEN_SLOT, OPEN_SLOT]
                        ])

      player1 = create_player(player1_name, PLAYER1_PIECE)
      player2 = create_player(player2_name, PLAYER2_PIECE)

      GameManager.new(
        player1: player1,
        player2: player2,
        board: board
      )
    end

    private

    # 概要: player_nameに応じてPlayerを作成する
    # 引数: player_name: plyaerの名前。数値
    # 戻り値: Playerクラスのインスタンス
    def create_player(player_name, piece)
      return RandomComPlayer.new(piece: piece) if  RANDOM_COM_PLAYER == player_name
      return OrdelyComPlayer.new(piece: piece) if  OEDERLY_COM_PLAYER == player_name

      UserPlayer.new(piece: piece) if USER_PLAYER == player_name
    end
  end
end

```


---

# 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/zui-zhong-zhang-ji-neng-zhui-jia/gamemanagerfactoryclassno.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.
