diff --git a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/HandDatabase.cs b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/HandDatabase.cs index ba30934..e65ba22 100644 --- a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/HandDatabase.cs +++ b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/HandDatabase.cs @@ -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 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()}; @@ -48,7 +50,12 @@ public HandDatabase(IBoard board, IObservable 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 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 diff --git a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TamObserver.cs b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TamObserver.cs index 4a507c6..acfe04c 100644 --- a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TamObserver.cs +++ b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TamObserver.cs @@ -7,11 +7,11 @@ namespace Azarashi.CerkeOnline.Domain.Entities.StandardizedRule.Hands /// 皇の動きを監視し, 皇再来を検出する. /// 皇が取られた場合の動作は未定義. /// - 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の座標 @@ -24,19 +24,19 @@ public TamObserver(IObservable onTurnChanged, IObservable 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; } diff --git a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TheFutileMove.cs b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TheFutileMove.cs index 57fcf6a..1cbbd0c 100644 --- a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TheFutileMove.cs +++ b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/Hands/TheFutileMove.cs @@ -6,7 +6,7 @@ namespace Azarashi.CerkeOnline.Domain.Entities.StandardizedRule.Hands /// /// 皇再来 /// - public class TheFutileMove : IHand + internal class TheFutileMove : IHand { public HandName Name { get; } public int Score { get; } @@ -23,7 +23,7 @@ public TheFutileMove(int score, TamObserver tamObserver) public int GetNumberOfSuccesses(IEnumerable pieces) { - return tamObserver.GetNumberOfTamenMako(); + return tamObserver.GetNumberOfTheFutileMove(); } } } \ No newline at end of file diff --git a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/StandardizedRuleGame.cs b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/StandardizedRuleGame.cs index de2df8f..3b10c4d 100644 --- a/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/StandardizedRuleGame.cs +++ b/Assets/Scripts/CerkeOnline/Domain/Entities/StandardizedRule/StandardizedRuleGame.cs @@ -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 @@ -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; } @@ -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(), 4); @@ -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 diff --git a/Assets/Scripts/Utilities/Pure/Assertion.meta b/Assets/Scripts/Utilities/Pure/Assertion.meta new file mode 100644 index 0000000..fdb89dd --- /dev/null +++ b/Assets/Scripts/Utilities/Pure/Assertion.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3795918399fdad940b3d8ad595e6e74a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utilities/Pure/Assertion/Assert.cs b/Assets/Scripts/Utilities/Pure/Assertion/Assert.cs new file mode 100644 index 0000000..b753c6d --- /dev/null +++ b/Assets/Scripts/Utilities/Pure/Assertion/Assert.cs @@ -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 expected, T actual, string message, IEqualityComparer comparer) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message, comparer); + [Conditional("UNITY_ASSERTIONS")] public static void AreEqual(T expected, T actual, string message) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, message); + [Conditional("UNITY_ASSERTIONS")] public static void AreEqual(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 expected, T actual) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual); + [Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(T expected, T actual, string message) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, message); + [Conditional("UNITY_ASSERTIONS")] public static void AreNotEqual(T expected, T actual, string message, IEqualityComparer 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 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 value, string message) where T : class => UnityEngine.Assertions.Assert.IsNotNull(value, message); + [Conditional("UNITY_ASSERTIONS")] public static void IsNull(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 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); + + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utilities/Pure/Assertion/Assert.cs.meta b/Assets/Scripts/Utilities/Pure/Assertion/Assert.cs.meta new file mode 100644 index 0000000..594ec2a --- /dev/null +++ b/Assets/Scripts/Utilities/Pure/Assertion/Assert.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 99a5a385098c2024bb5ef3c165929fdc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: