Skip to content

Commit

Permalink
皇に関する役のバグを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
azrsh committed Aug 4, 2020
1 parent 8af629d commit 92278ae
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ namespace Azarashi.CerkeOnline.Domain.Entities.StandardizedRule
*/
internal class HandDatabase : IHandDatabase
{
const int NumberOfPieceStacksProviders = 10;

readonly IHand[] hands;
readonly OverwriteHandPair[] overwriteHandPairs;

public HandDatabase(IBoard board, IObservable<Unit> onTurnChanged)
public HandDatabase()
{
const int NumberOfPieceStacksProviders = 10;
//Stateless hands
IPieceStacksProvider[] pieceStacksProviders = new IPieceStacksProvider[NumberOfPieceStacksProviders]
{ new TheUnbeatable(), new TheSocialOrder(), new TheCulture(), new TheAttack(), new TheKing(), new TheAnimals(),
new TheDeadlyArmy(), new TheCavalry(), new TheArmy(), new TheComrades()};
Expand All @@ -48,7 +50,12 @@ public HandDatabase(IBoard board, IObservable<Unit> onTurnChanged)
hands[i * 2 + 1] = new FlashHand(pieceStacksProviders[i], baseScores[i] + bounus);
overwriteHandPairs[i] = new OverwriteHandPair(hands[i * 2], hands[i * 2 + 1]);
}
}

public void Reset(IBoard board, IObservable<Unit> onTurnChanged)
{
//Reset stateful hands
//外部に追い出して季ごとのResetを不要にすべきかも
var tam = board.SearchPiece(Terminologies.PieceName.Minds);
var tamObserver = new TamObserver(onTurnChanged, board.OnEveruValueChanged, tam);
hands[NumberOfPieceStacksProviders * 2] = new TheStepping(-5, (ISteppedObservable)tam); //Unsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Azarashi.CerkeOnline.Domain.Entities.StandardizedRule.Hands
/// 皇の動きを監視し, 皇再来を検出する.
/// 皇が取られた場合の動作は未定義.
/// </summary>
public class TamObserver
internal class TamObserver
{
int numberOfTamenMako = 0; //皇再来の成立回数
bool isMoved = false; //現在のターン中に駒が動いたか
bool isPrevoiusMoved = false; //前回のターンに駒が動いたか
bool isCurrentTurnMoved = false; //現在のターン中に駒が動いたか
bool isPrevoiusTurnMoved = false; //前回のターンに駒が動いたか
PublicDataType.IntegerVector2 previousTurnPosition; //前回のターン終了時の皇の座標
PublicDataType.IntegerVector2 currentPosition; //現在のtamの座標

Expand All @@ -24,19 +24,19 @@ public TamObserver(IObservable<Unit> onTurnChanged, IObservable<Unit> onEveruVal

void OnTamMoved(PublicDataType.IntegerVector2 position)
{
if (isPrevoiusMoved || (isMoved && previousTurnPosition == position)) numberOfTamenMako++;
isMoved = true;
if (isPrevoiusTurnMoved || (isCurrentTurnMoved && previousTurnPosition == position)) numberOfTamenMako++;
isCurrentTurnMoved = true;
currentPosition = position;
}

void OnTurnChanged(Unit unit)
{
isPrevoiusMoved = isMoved;
isMoved = false;
isPrevoiusTurnMoved = isCurrentTurnMoved;
isCurrentTurnMoved = false;
previousTurnPosition = currentPosition;
}

public int GetNumberOfTamenMako()
public int GetNumberOfTheFutileMove()
{
return numberOfTamenMako;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Azarashi.CerkeOnline.Domain.Entities.StandardizedRule.Hands
/// <summary>
/// 皇再来
/// </summary>
public class TheFutileMove : IHand
internal class TheFutileMove : IHand
{
public HandName Name { get; }
public int Score { get; }
Expand All @@ -23,7 +23,7 @@ public TheFutileMove(int score, TamObserver tamObserver)

public int GetNumberOfSuccesses(IEnumerable<IReadOnlyPiece> pieces)
{
return tamObserver.GetNumberOfTamenMako();
return tamObserver.GetNumberOfTheFutileMove();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using UniRx;
using Azarashi.Utilities;
using Azarashi.Utilities.Assertions;
using static Azarashi.CerkeOnline.Domain.Entities.Terminologies;

namespace Azarashi.CerkeOnline.Domain.Entities.StandardizedRule
Expand All @@ -11,7 +12,8 @@ public class StandardizedRuleGame : IGame
{
public ISeasonSequencer SeasonSequencer => seasonSequencer;
public IBoard Board { get; private set; }
public IHandDatabase HandDatabase { get; private set; }
public IHandDatabase HandDatabase => handDatabase;
HandDatabase handDatabase;
public IScoreHolder ScoreHolder { get; }
public int ScoreRate { get; private set; } = 1;
public FirstOrSecond CurrentTurn { get; private set; }
Expand Down Expand Up @@ -45,9 +47,10 @@ public StandardizedRuleGame(Encampment firstPlayerEncampment, IReadOnlyServiceLo
ScoreHolder.GetScore(frontPlayer).Where(value => value == 0).Subscribe(_ => gameEndSubject.OnNext(Unit.Default));
ScoreHolder.GetScore(backPlayer).Where(value => value == 0).Subscribe(_ => gameEndSubject.OnNext(Unit.Default));

handDatabase = new HandDatabase();

//seasonSequencer.OnEndは季の開始の呼び出しと一体化している。
//OnSeasonEndは季の開始前に呼び出されることが保証されている。

StartNextSeason();
handChangeObserver = new HandChangeObserver(HandDatabase, OnTurnEnd);
seasonSequencer = new SeasonSequencer(handChangeObserver.Observable, serviceLocator.GetInstance<ISeasonDeclarationProvider>(), 4);
Expand Down Expand Up @@ -91,12 +94,16 @@ public void TurnEnd()

void StartNextSeason()
{
Assert.IsNotNull(handDatabase);

CurrentTurn = FirstOrSecond.First;

var frontPlayer = GetPlayer(Encampment.Front);
var backPlayer = GetPlayer(Encampment.Back);
Board = BoardFactory.Create(frontPlayer, backPlayer);
HandDatabase = new HandDatabase(Board, OnTurnChanged);
Board = BoardFactory.Create(frontPlayer, backPlayer);

handDatabase.Reset(Board, onTurnChanged);

handChangeObserver?.Reset();

//PickOut All
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Utilities/Pure/Assertion.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions Assets/Scripts/Utilities/Pure/Assertion/Assert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Diagnostics;

namespace Azarashi.Utilities.Assertions
{
public static class Assert
{
[Conditional("UNITY_ASSERTIONS")] public static void AreApproximatelyEqual(float expected, float actual, float tolerance, string message) => UnityEngine.Assertions.Assert.AreApproximatelyEqual(expected, actual, tolerance, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreApproximatelyEqual(float expected, float actual, float tolerance) => UnityEngine.Assertions.Assert.AreApproximatelyEqual(expected, actual, tolerance);
[Conditional("UNITY_ASSERTIONS")] public static void AreApproximatelyEqual(float expected, float actual) => UnityEngine.Assertions.Assert.AreApproximatelyEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreApproximatelyEqual(float expected, float actual, string message) => UnityEngine.Assertions.Assert.AreApproximatelyEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(ushort expected, ushort actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(ushort expected, ushort actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(byte expected, byte actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(uint expected, uint actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(char expected, char actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(char expected, char actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(sbyte expected, sbyte actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(sbyte expected, sbyte actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(int expected, int actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(int expected, int actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(uint expected, uint actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(byte expected, byte actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(short expected, short actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(short expected, short actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual<T>(T expected, T actual, string message, IEqualityComparer<T> comparer) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message, comparer);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual<T>(T expected, T actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual<T>(T expected, T actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(ulong expected, ulong actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(ulong expected, ulong actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(UnityEngine.Object expected, UnityEngine.Object actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(long expected, long actual) => UnityEngine.Assertions.Assert.AreEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreEqual(long expected, long actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotApproximatelyEqual(float expected, float actual, string message) => UnityEngine.Assertions.Assert.AreNotApproximatelyEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotApproximatelyEqual(float expected, float actual, float tolerance, string message) => UnityEngine.Assertions.Assert.AreNotApproximatelyEqual(expected, actual, tolerance, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotApproximatelyEqual(float expected, float actual, float tolerance) => UnityEngine.Assertions.Assert.AreNotApproximatelyEqual(expected, actual, tolerance);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotApproximatelyEqual(float expected, float actual) => UnityEngine.Assertions.Assert.AreNotApproximatelyEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(short expected, short actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(short expected, short actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(long expected, long actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(uint expected, uint actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(ushort expected, ushort actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(ushort expected, ushort actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(int expected, int actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(int expected, int actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(long expected, long actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(uint expected, uint actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(sbyte expected, sbyte actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(char expected, char actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual<T>(T expected, T actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual<T>(T expected, T actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual<T>(T expected, T actual, string message, IEqualityComparer<T> comparer) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message, comparer);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(char expected, char actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(UnityEngine.Object expected, UnityEngine.Object actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(byte expected, byte actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(byte expected, byte actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(ulong expected, ulong actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(sbyte expected, sbyte actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual);
[Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(ulong expected, ulong actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message);
[Conditional("UNITY_ASSERTIONS")] public static void IsFalse(bool condition) => UnityEngine.Assertions.Assert.IsFalse(condition);
[Conditional("UNITY_ASSERTIONS")] public static void IsNotNull<T>(T value) where T : class => UnityEngine.Assertions.Assert.IsNotNull(value);
[Conditional("UNITY_ASSERTIONS")] public static void IsNotNull(UnityEngine.Object value, string message) => UnityEngine.Assertions.Assert.IsNotNull(value, message);
[Conditional("UNITY_ASSERTIONS")] public static void IsNotNull<T>(T value, string message) where T : class => UnityEngine.Assertions.Assert.IsNotNull(value, message);
[Conditional("UNITY_ASSERTIONS")] public static void IsNull<T>(T value, string message) where T : class => UnityEngine.Assertions.Assert.IsNull(value, message);
[Conditional("UNITY_ASSERTIONS")] public static void IsNull(UnityEngine.Object value, string message) => UnityEngine.Assertions.Assert.IsNull(value, message);
[Conditional("UNITY_ASSERTIONS")] public static void IsNull<T>(T value) where T : class => UnityEngine.Assertions.Assert.IsNull(value);
[Conditional("UNITY_ASSERTIONS")] public static void IsTrue(bool condition, string message) => UnityEngine.Assertions.Assert.IsTrue(condition, message);
[Conditional("UNITY_ASSERTIONS")] public static void IsTrue(bool condition) => UnityEngine.Assertions.Assert.IsTrue(condition);

}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Utilities/Pure/Assertion/Assert.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 92278ae

Please sign in to comment.