# ゲーム板の出力関数

三目並べのゲーム板を出力する関数を実装します。

全てmain.rbに記載していくようにお願いします。

## ゲーム板を定義する

ゲーム板を表現するのに3 x 3の二次元配列を使います。

```ruby
board =  [[], [], []]
```

プレイヤー1のコマが置いてある状態を1

プレイヤー2のコマが置いてある状態を2

何も置いていない状態を0とします

なのでゲーム板の初期状態は以下のようになるでしょう

```ruby
board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
```

## ゲーム板の状態を出力できるようにする

ゲーム板の状態を出力できるようにします

```ruby
# 説明: ゲーム板の状態をコンソールに出力する
# 引数: board: ゲーム板, 3 x 3の二次元配列
# 戻り値: なし
def print_board board
  puts board
end
```

print\_board関数を呼び出してみましょう

```ruby
# 説明: ゲーム板の状態をコンソールに出力する
...

board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

print_board(board)
```

実行すれば、以下のような出力になると思います

```
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
```

これでは、ゲームっぽくありませんね。

少し修正を加えてみましょう。

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

print\_boardメソッドを修正して見やすくしてみよう
{% endhint %}

私は以下のように修正してみました。

```ruby
# 説明: ゲーム板の状態をコンソールに出力する
# 引数: board: ゲーム板, 3 x 3の二次元配列
# 戻り値: なし
def print_board board
  puts ""
  board.each do |row|
    row.each do |e|
      print " N " if 0 == e
      print " o " if 1 == e
      print " x " if 2 == e
    end
    puts ""
  end
  puts ""
end
```

この状態でもう一度実行してみます。

```
 N  N  N 
 N  N  N 
 N  N  N 
```

以前に実装した物より見やすくなりました！


---

# Agent Instructions: 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:

```
GET https://kashiwara.gitbook.io/rubydesurufurusukuratchibe/rojikkuno/gmuno.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
