Skip to content

Commit

Permalink
TurnをOthelloに改名 #55
Browse files Browse the repository at this point in the history
  • Loading branch information
ebinase committed May 7, 2022
1 parent bb592be commit 4fe3c7e
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/OthelloCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Packages\Models\Othello\Board\Color\Color;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Board\Position\PositionConverterTrait;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;

class OthelloCommand extends Command
{
Expand Down Expand Up @@ -110,7 +110,7 @@ public function handle()
];
}

$turn = Turn::init();
$turn = Othello::init();
while (!$turn->finishedLastTurn() && $turn->isContinuable()) { // 最終ターンが終了しておらず、プレイが継続可能な状態の時
$this->info($turn->getTurnNumber() . 'ターン目');

Expand Down
4 changes: 2 additions & 2 deletions packages/Models/Bot/BotInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Packages\Models\Bot\Calculators\CalculatorInterface;
use Packages\Models\Bot\Levels\BotLevel;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;

interface BotInterface
{
public function run(Turn $turn): Position;
public function run(Othello $turn): Position;
}
4 changes: 2 additions & 2 deletions packages/Models/Bot/Bots/RandomBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Packages\Models\Bot\BotInterface;
use Packages\Models\Bot\Calculators\Random\RandomCalculator;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;

class RandomBot implements BotInterface
{
public function run(Turn $turn): Position
public function run(Othello $turn): Position
{
$board = $turn->getBoard();
$color = $turn->getPlayableColor();
Expand Down
4 changes: 2 additions & 2 deletions packages/Models/Bot/Bots/SelfOpennessBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use Packages\Models\Bot\Calculators\Openness\SelfOpennessCalculator;
use Packages\Models\Bot\Calculators\Random\RandomCalculator;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;

class SelfOpennessBot implements BotInterface
{
public function run(Turn $turn): Position
public function run(Othello $turn): Position
{
// 周囲の空きマスの数 => Position[]、の形式で結果を取得
$result = SelfOpennessCalculator::calculate($turn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Packages\Models\Othello\Board\Board;
use Packages\Models\Othello\Board\Color\Color;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;

class SelfOpennessCalculator
{
/**
* @param Turn $turn
* @param Othello $turn
* @return array{openness:int, positions:array<Position>}
*/
public static function calculate(Turn $turn): array
public static function calculate(Othello $turn): array
{
$board = $turn->getBoard();
$color = $turn->getPlayableColor();
Expand Down
12 changes: 6 additions & 6 deletions packages/Models/GameOrganizer/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Packages\Models\GameOrganizer\Participant\ParticipantInterface;
use Packages\Models\Othello\Board\Color\Color;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;

class Game
{
Expand All @@ -16,7 +16,7 @@ private function __construct(
private GameMode $gameMode,
private Participants $participants,
private GameStatus $gameStatus,
private Turn $turn,
private Othello $turn,
)
{
// ゲームモードと実際の参加者の組み合わせをチェック
Expand Down Expand Up @@ -49,11 +49,11 @@ public static function init(string $id, GameMode $gameMode, Participants $partic
gameMode: $gameMode,
participants: $participants,
gameStatus: GameStatus::playing(),
turn: Turn::init()
turn: Othello::init()
);
}

public static function make(string $id, GameMode $gameMode, Participants $participants, GameStatus $status, Turn $turn)
public static function make(string $id, GameMode $gameMode, Participants $participants, GameStatus $status, Othello $turn)
{
return new Game(
id: $id,
Expand Down Expand Up @@ -169,9 +169,9 @@ public function getStatus(): GameStatus
}

/**
* @return Turn
* @return Othello
*/
public function getTurn(): Turn
public function getTurn(): Othello
{
return $this->turn;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Packages\Models\Othello\Turn;
namespace Packages\Models\Othello\Othello;

use Packages\Models\Othello\Board\Board;
use Packages\Models\Othello\Board\Color\Color;
use Packages\Models\Othello\Board\Position\Position;

class Turn
class Othello
{
// スキップの連続を許容する回数
const MAX_CONTINUOUS_SKIP_COUNT = 1;
Expand All @@ -23,19 +23,19 @@ private function __construct(
}
}

public static function init(): Turn
public static function init(): Othello
{
return new Turn(
return new Othello(
turnNumber: 1,
playableColor: Color::white(),
board: Board::init(),
skipCount: 0,
);
}

public static function make(int $turnNumber, Color $playableColor, Board $board, int $skipCount): Turn
public static function make(int $turnNumber, Color $playableColor, Board $board, int $skipCount): Othello
{
return new Turn(
return new Othello(
turnNumber: $turnNumber,
playableColor: $playableColor,
board: $board,
Expand All @@ -50,7 +50,7 @@ public static function make(int $turnNumber, Color $playableColor, Board $board,
* 盤面:コマを置いて更新。スキップの場合は現在のものをそのまま設定
* 連続スキップ数:スキップ時+1。スキップしない場合は0にリセット
*/
public function next(?Position $position = null): Turn
public function next(?Position $position = null): Othello
{
// ゲームが終了している場合
if ($this->finishedLastTurn()) throw new \RuntimeException();
Expand All @@ -59,7 +59,7 @@ public function next(?Position $position = null): Turn

// スキップするときは盤面はそのままで、スキップカウントを加算する
if ($this->mustSkip()) {
return new Turn(
return new Othello(
$this->turnNumber + 1,
$this->playableColor->opposite(),
$this->board,
Expand All @@ -73,7 +73,7 @@ public function next(?Position $position = null): Turn
// 指定された場所にコマを置くことができるか確認
if (!$this->board->isValid($position, $this->playableColor)) throw new \Exception('指定された場所に置くことができません。');

return new Turn(
return new Othello(
$this->turnNumber + 1,
$this->playableColor->opposite(),
$this->board->update($position, $this->playableColor),
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Models/Bot/BotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Packages\Models\Bot\BotType;
use Packages\Models\Bot\Levels\LevelFactory;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;
use Tests\TestCase;

class BotTest extends TestCase
Expand All @@ -15,7 +15,7 @@ class BotTest extends TestCase
public function 全てのボットが期待した通りの動作をする()
{
// given:
$turn = Turn::init();
$turn = Othello::init();
foreach (BotType::cases() as $type) {
$bots[] = BotFactory::make($type);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Models/GameOrganizer/GameFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Packages\Models\GameOrganizer\Participant\BotParticipant;
use Packages\Models\GameOrganizer\Participant\Player;
use Packages\Models\GameOrganizer\Participants;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;
use Tests\TestCase;

class GameFactoryTest extends TestCase
Expand All @@ -25,7 +25,7 @@ public function 共通項目()
// then:
self::assertTrue(\Str::isUuid($game->getId()));
self::assertTrue($game->getStatus()->toCode() === GameStatus::GAME_STATUS_PLAYING);
self::assertTrue($game->getTurn() == Turn::init());
self::assertTrue($game->getTurn() == Othello::init());
}

/** @test */
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Models/GameOrganizer/GameProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Packages\Models\Othello\Board\Board;
use Packages\Models\Othello\Board\Color\Color;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;
use Tests\TestCase;

class GameProcessTest extends TestCase
Expand Down Expand Up @@ -55,7 +55,7 @@ public function ゲームを進行させる場合はステータスがプレー
$blackPlayer = new Player('02', 'player_black');
$participants = Participants::make($whitePlayer, $blackPlayer);
$status = GameStatus::finish();
$turn = Turn::init();
$turn = Othello::init();

$game = Game::make($gameId, $mode, $participants, $status, $turn);

Expand Down
24 changes: 12 additions & 12 deletions tests/Feature/Models/Othello/Turn/TurnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Packages\Models\Othello\Board\Board;
use Packages\Models\Othello\Board\Color\Color;
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Turn\Turn;
use Packages\Models\Othello\Othello\Othello;
use Tests\TestCase;

class TurnTest extends TestCase
Expand All @@ -17,7 +17,7 @@ public function ターン初期化()
// given:

// when:
$turn = Turn::init();
$turn = Othello::init();

// then:
self::assertSame(1, $turn->getTurnNumber(), 'ターン数は1から始まる');
Expand All @@ -30,7 +30,7 @@ public function ターン初期化()
public function ターン更新()
{
// given:
$turn = Turn::init(); // 1ターン目
$turn = Othello::init(); // 1ターン目
$move = Position::make([4, 6]); // 先行プレイヤーの1ターン目の指した場所
// when:
$next = $turn->next($move); // ターンを進める
Expand All @@ -47,7 +47,7 @@ public function ターン更新()
public function おけない場所を指定された時は例外を出す()
{
// given:
$turn = Turn::init(); // 1ターン目
$turn = Othello::init(); // 1ターン目
// when:
$move = Position::make([1, 1]); // おけない場所
// then:
Expand All @@ -65,8 +65,8 @@ public function 盤面に空いているマスがなくなった時が最後の
$fullBoard = Board::make(Matrix::init(8, 8, Color::white()->toCode())->toArray());

// when:
$firstTurn = Turn::init();
$lastTurn = Turn::make(20, Color::white(), $fullBoard, 0);
$firstTurn = Othello::init();
$lastTurn = Othello::make(20, Color::white(), $fullBoard, 0);
// then:
self::assertSame(false, $firstTurn->finishedLastTurn());
self::assertSame(true, $lastTurn->finishedLastTurn());
Expand All @@ -79,9 +79,9 @@ public function スキップが2ターン続いたらそれ以降は一切更新
$position = Position::make([4, 6]);

// when:
$turnSkip0 = Turn::make(20, Color::white(), Board::init(), 0);
$turnSkip1 = Turn::make(20, Color::white(), Board::init(), 1);
$turnSkip2 = Turn::make(20, Color::white(), Board::init(), 2);
$turnSkip0 = Othello::make(20, Color::white(), Board::init(), 0);
$turnSkip1 = Othello::make(20, Color::white(), Board::init(), 1);
$turnSkip2 = Othello::make(20, Color::white(), Board::init(), 2);

// then:
// isContinuable()テスト
Expand Down Expand Up @@ -118,7 +118,7 @@ public function 盤面における場所がなかったらスキップカウン
$board = Board::make($board);

// when:
$turn1 = Turn::make(1, Color::black(), $board, 0);
$turn1 = Othello::make(1, Color::black(), $board, 0);
$turn2 = $turn1->next();
$turn3 = $turn2->next();

Expand Down Expand Up @@ -154,7 +154,7 @@ public function スキップされなかった時、カウントは0に戻る()

// when:
// 黒のターンとして生成
$turn1 = Turn::make(1, Color::black(), $board, 0);
$turn1 = Othello::make(1, Color::black(), $board, 0);
// 黒が行動(スキップ)
$turn2 = $turn1->next();
// 白が行動
Expand All @@ -172,7 +172,7 @@ public function 置ける場所があるのにスキップしようとした場
{
// given:
// when:
$turn = Turn::init(); // 1ターン目
$turn = Othello::init(); // 1ターン目
// then:
$this->expectException(\Exception::class);
// 置ける場所があるのに場所指定なしで更新した場合
Expand Down

0 comments on commit 4fe3c7e

Please sign in to comment.