First pass. Needs testing.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Shogi.Domain.YetToBeAssimilatedIntoDDD;
|
||||
using System.Threading.Tasks;
|
||||
namespace Shogi.Domain.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
@@ -173,9 +172,8 @@ public sealed class ShogiBoard
|
||||
}
|
||||
|
||||
|
||||
private async Task<GameOverResult> EvaluateGameOver()
|
||||
private GameOverResult EvaluateGameOver()
|
||||
{
|
||||
|
||||
if (!BoardState.InCheck.HasValue)
|
||||
{
|
||||
return GameOverResult.GameIsNotOver;
|
||||
@@ -198,43 +196,20 @@ public sealed class ShogiBoard
|
||||
var simState = new BoardState(BoardState);
|
||||
simState.Move(notation, Notation.ToBoardNotation(move), false);
|
||||
var inCheckResult = IsEitherPlayerInCheck(simState);
|
||||
if (inCheckResult == InCheckResult.)
|
||||
var isStillInCheck = BoardState.InCheck == WhichPlayer.Player1
|
||||
? inCheckResult.HasFlag(InCheckResult.Player1InCheck)
|
||||
: inCheckResult.HasFlag(InCheckResult.Player2InCheck);
|
||||
|
||||
if (!isStillInCheck)
|
||||
{
|
||||
return GameOverResult.GameIsNotOver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// while (tasks.Any()) var result = Task.WhenAny(tasks); // Then check for GameIsNotOver and maybe return early.
|
||||
|
||||
|
||||
var gameOverResult = BoardState.State
|
||||
.Where(kvp => kvp.Value != null)
|
||||
.Cast<KeyValuePair<string, Piece>>()
|
||||
.Aggregate(GameOverResult.GameIsNotOver, (inCheckResult, kvp) =>
|
||||
{
|
||||
var newInCheckResult = inCheckResult;
|
||||
var threatPiece = kvp.Value;
|
||||
var opposingKingPosition = Notation.FromBoardNotation(kingInCheck.Single(king => king.Value.Owner != threatPiece.Owner).Key);
|
||||
var positionsThreatened = threatPiece.GetPathFromStartToEnd(Notation.FromBoardNotation(kvp.Key), opposingKingPosition);
|
||||
|
||||
foreach (var position in positionsThreatened)
|
||||
{
|
||||
// No piece at this position, so pathing is unobstructed. Continue pathing.
|
||||
if (simState[position] == null) continue;
|
||||
|
||||
var threatenedPiece = simState[position]!;
|
||||
if (threatenedPiece.WhichPiece == WhichPiece.King && threatenedPiece.Owner != threatPiece.Owner)
|
||||
{
|
||||
newInCheckResult |= threatenedPiece.Owner == WhichPlayer.Player1 ? InCheckResult.Player1InCheck : InCheckResult.Player2InCheck;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return newInCheckResult;
|
||||
});
|
||||
|
||||
return GameOverResult.GameIsNotOver;
|
||||
return BoardState.InCheck == WhichPlayer.Player1
|
||||
? GameOverResult.Player2Wins
|
||||
: GameOverResult.Player1Wins;
|
||||
|
||||
Vector2[] GetPossiblePositionsForPiece(Vector2 piecePosition, Piece piece)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using static Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing.Path;
|
||||
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
|
||||
@@ -20,4 +19,6 @@ public record Path
|
||||
Step = step;
|
||||
this.Distance = distance;
|
||||
}
|
||||
|
||||
public Path Invert() => new(Vector2.Negate(Step), Distance);
|
||||
}
|
||||
Reference in New Issue
Block a user