firefish/src/docs/reversi-bot.ja-JP.md
syuilo f0a29721c9
Use PostgreSQL instead of MongoDB (#4572)
* wip

* Update note.ts

* Update timeline.ts

* Update core.ts

* wip

* Update generate-visibility-query.ts

* wip

* wip

* wip

* wip

* wip

* Update global-timeline.ts

* wip

* wip

* wip

* Update vote.ts

* wip

* wip

* Update create.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update files.ts

* wip

* wip

* Update CONTRIBUTING.md

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update read-notification.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update cancel.ts

* wip

* wip

* wip

* Update show.ts

* wip

* wip

* Update gen-id.ts

* Update create.ts

* Update id.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Docker: Update files about Docker (#4599)

* Docker: Use cache if files used by `yarn install` was not updated

This patch reduces the number of times to installing node_modules.
For example, `yarn install` step will be skipped when only ".config/default.yml" is updated.

* Docker: Migrate MongoDB to Postgresql

Misskey uses Postgresql as a database instead of Mongodb since version 11.

* Docker: Uncomment about data persistence

This patch will save a lot of databases.

* wip

* wip

* wip

* Update activitypub.ts

* wip

* wip

* wip

* Update logs.ts

* wip

* Update drive-file.ts

* Update register.ts

* wip

* wip

* Update mentions.ts

* wip

* wip

* wip

* Update recommendation.ts

* wip

* Update index.ts

* wip

* Update recommendation.ts

* Doc: Update docker.ja.md and docker.en.md (#1) (#4608)

Update how to set up misskey.

* wip

* ✌️

* wip

* Update note.ts

* Update postgre.ts

* wip

* wip

* wip

* wip

* Update add-file.ts

* wip

* wip

* wip

* Clean up

* Update logs.ts

* wip

* 🍕

* wip

* Ad notes

* wip

* Update api-visibility.ts

* Update note.ts

* Update add-file.ts

* tests

* tests

* Update postgre.ts

* Update utils.ts

* wip

* wip

* Refactor

* wip

* Refactor

* wip

* wip

* Update show-users.ts

* Update update-instance.ts

* wip

* Update feed.ts

* Update outbox.ts

* Update outbox.ts

* Update user.ts

* wip

* Update list.ts

* Update update-hashtag.ts

* wip

* Update update-hashtag.ts

* Refactor

* Update update.ts

* wip

* wip

* ✌️

* clean up

* docs

* Update push.ts

* wip

* Update api.ts

* wip

* ✌️

* Update make-pagination-query.ts

* ✌️

* Delete hashtags.ts

* Update instances.ts

* Update instances.ts

* Update create.ts

* Update search.ts

* Update reversi-game.ts

* Update signup.ts

* Update user.ts

* id

* Update example.yml

* 🎨

* objectid

* fix

* reversi

* reversi

* Fix bug of chart engine

* Add test of chart engine

* Improve test

* Better testing

* Improve chart engine

* Refactor

* Add test of chart engine

* Refactor

* Add chart test

* Fix bug

* コミットし忘れ

* Refactoring

* ✌️

* Add tests

* Add test

* Extarct note tests

* Refactor

* 存在しないユーザーにメンションできなくなっていた問題を修正

* Fix bug

* Update update-meta.ts

* Fix bug

* Update mention.vue

* Fix bug

* Update meta.ts

* Update CONTRIBUTING.md

* Fix bug

* Fix bug

* Fix bug

* Clean up

* Clean up

* Update notification.ts

* Clean up

* Add mute tests

* Add test

* Refactor

* Add test

* Fix test

* Refactor

* Refactor

* Add tests

* Update utils.ts

* Update utils.ts

* Fix test

* Update package.json

* Update update.ts

* Update manifest.ts

* Fix bug

* Fix bug

* Add test

* 🎨

* Update endpoint permissions

* Updaye permisison

* Update person.ts

#4299

* データベースと同期しないように

* Fix bug

* Fix bug

* Update reversi-game.ts

* Use a feature of Node v11.7.0 to extract a public key (#4644)

* wip

* wip

* ✌️

* Refactoring

#1540

* test

* test

* test

* test

* test

* test

* test

* Fix bug

* Fix test

* 🍣

* wip

* #4471

* Add test for #4335

* Refactor

* Fix test

* Add tests

* 🕓

* Fix bug

* Add test

* Add test

* rename

* Fix bug
2019-04-07 21:50:36 +09:00

6.1 KiB

MisskeyリバーシBotの開発

Misskeyのリバーシ機能に対応したBotの開発方法をここに記します。

  1. games/reversiストリームに以下のパラメータを付けて接続する:

    • i: botアカウントのAPIキー
  2. 対局への招待が来たら、ストリームからinvitedイベントが流れてくる

    • イベントの中身に、parentという名前で対局へ誘ってきたユーザーの情報が含まれている
  3. games/reversi/matchへ、user_idとしてparentidが含まれたリクエストを送信する

  4. 上手くいくとゲーム情報が返ってくるので、games/reversi-gameストリームへ、以下のパラメータを付けて接続する:

    • i: botアカウントのAPIキー
    • game: gameid
  5. この間、相手がゲームの設定を変更するとその都度update-settingsイベントが流れてくるので、必要であれば何かしらの処理を行う

  6. 設定に満足したら、{ type: 'accept' }メッセージをストリームに送信する

  7. ゲームが開始すると、startedイベントが流れてくる

    • イベントの中身にはゲーム情報が含まれている
  8. 石を打つには、ストリームに{ type: 'set', pos: <位置> }を送信する(位置の計算方法は後述)

  9. 相手または自分が石を打つと、ストリームからsetイベントが流れてくる

    • colorとして石の色が含まれている
    • posとして位置情報が含まれている

位置の計算法

8x8のマップを考える場合、各マスの位置(Posと呼びます)は次のようになっています:

+--+--+--+--+--+--+--+--+
| 0| 1| 2| 3| 4| 5| 6| 7|
+--+--+--+--+--+--+--+--+
| 8| 9|10|11|12|13|14|15|
+--+--+--+--+--+--+--+--+
|16|17|18|19|20|21|22|23|
...

X,Y座標 から Pos に変換する

pos = x + (y * mapWidth)

mapWidthは、ゲーム情報のmapから、次のようにして計算できます:

mapWidth = map[0].length

Pos から X,Y座標 に変換する

x = pos % mapWidth
y = Math.floor(pos / mapWidth)

マップ情報

マップ情報は、ゲーム情報のmapに入っています。 文字列の配列になっており、ひとつひとつの文字がマス情報を表しています。 それをもとにマップのデザインを知る事が出来ます:

  • (スペース) ... マス無し
  • - ... マス
  • b ... 初期配置される黒石
  • w ... 初期配置される白石

例えば、4*4の次のような単純なマップがあるとします:

+---+---+---+---+
|   |   |   |   |
+---+---+---+---+
|   | ○ | ● |   |
+---+---+---+---+
|   | ● | ○ |   |
+---+---+---+---+
|   |   |   |   |
+---+---+---+---+

この場合、マップデータはこのようになります:

['----', '-wb-', '-bw-', '----']

ユーザーにフォームを提示して対話可能Botを作成する

ユーザーとのコミュニケーションを行うため、ゲームの設定画面でユーザーにフォームを提示することができます。 例えば、Botの強さをユーザーが設定できるようにする、といったシナリオが考えられます。

フォームを提示するには、reversi-gameストリームに次のメッセージを送信します:

{
  type: 'init-form',
  body: [フォームコントロールの配列]
}

フォームコントロールの配列については今から説明します。 フォームコントロールは、次のようなオブジェクトです:

{
  id: 'switch1',
  type: 'switch',
  label: 'Enable hoge',
  value: false
}

id ... コントロールのID。 type ... コントロールの種類。後述します。 label ... コントロールと一緒に表記するテキスト。 value ... コントロールのデフォルト値。

フォームの操作を受け取る

ユーザーがフォームを操作すると、ストリームからupdate-formイベントが流れてきます。 イベントの中身には、コントロールのIDと、ユーザーが設定した値が含まれています。 例えば、上で示したスイッチをユーザーがオンにしたとすると、次のイベントが流れてきます:

{
  id: 'switch1',
  value: true
}

フォームコントロールの種類

スイッチ

type: switch スイッチを表示します。何かの機能をオン/オフさせたい場合に有用です。

プロパティ

label ... スイッチに表記するテキスト。

ラジオボタン

type: radio ラジオボタンを表示します。選択肢を提示するのに有用です。例えば、Botの強さを設定させるなどです。

プロパティ

items ... ラジオボタンの選択肢。例:

items: [{
  label: '弱',
  value: 1
}, {
  label: '中',
  value: 2
}, {
  label: '強',
  value: 3
}]

スライダー

type: slider スライダーを表示します。

プロパティ

min ... スライダーの下限。 max ... スライダーの上限。 step ... 入力欄で刻むステップ値。

テキストボックス

type: textbox テキストボックスを表示します。ユーザーになにか入力させる一般的な用途に利用できます。

ユーザーにメッセージを表示する

設定画面でユーザーと対話する、フォーム以外のもうひとつの方法がこれです。ユーザーになにかメッセージを表示することができます。 例えば、ユーザーがBotの対応していないモードやマップを選択したとき、警告を表示するなどです。 メッセージを表示するには、次のメッセージをストリームに送信します:

{
  type: 'message',
  body: {
    text: 'メッセージ内容',
    type: 'メッセージの種類'
  }
}

メッセージの種類: success, info, warning, error

投了する

投了をするには、このエンドポイントにリクエストします。