LoginSignup
1
0

More than 3 years have passed since last update.

PowerShellでオセロ

Last updated at Posted at 2020-12-08

はじめに

PowerShellだったら、途中経過をファイルに保存することなくオセロを実装できますね。

というわけで作ってみました。

使い方

.ps1ファイルなので、管理者権限でPowerShellを起動して、Set-ExecutionPolicyでファイルの実行を許可しておいてください。

Set-ExecutionPolicy RemoteSigned
> # 開始
> $board = .\Othello.ps1;
> 
> # 盤面表示
> $board.Show()

A  B  C  D  E  F  G  H  Index
-  -  -  -  -  -  -  -  -----
                    0
                    1
                    2
      〇 ●            3
      ●  〇           4
                    5
                    6
                    7
>
> # 手番
> # やっつけなので英数の順で小文字不可。
> $board.Set('F4')
●を置きました。次は〇

A  B  C  D  E  F  G  H  Index
-  -  -  -  -  -  -  -  -----
                    0
                    1
                    2
      〇 ●            3
      ●  ●  ●          4
                    5
                    6
                    7

>

自動再生

PowerShellなので次のようにパイプラインで配列を渡せばプレーを自動再生できます。

> $board = .\Othello.ps1; $board.Show()

A  B  C  D  E  F  G  H  Index
-  -  -  -  -  -  -  -  -----
                    0
                    1
                    2
      〇 ●            3
      ●  〇           4
                    5
                    6
                    7

> 'F4','D5','C4','F3','E2','F5','G4','E5','E6' | %{$board.Set($_)}
●を置きました。次は〇

A  B  C  D  E  F  G  H  Index
-  -  -  -  -  -  -  -  -----
                    0
                    1
                    2
      〇 ●            3
      ●  ●  ●          4
                    5
                    6
                    7


# 中略

終了 ●13 〇0

A  B  C  D  E  F  G  H  Index
-  -  -  -  -  -  -  -  -----
                    0
                    1
        ●            2
      ●  ●  ●          3
    ●  ●  ●  ●  ●        4
      ●  ●  ●          5
        ●            6
                    7

>

ソースコード

Othello.ps1

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0