本文整理汇总了C#中Game.GetPieceAt方法的典型用法代码示例。如果您正苦于以下问题:C# Game.GetPieceAt方法的具体用法?C# Game.GetPieceAt怎么用?C# Game.GetPieceAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game.GetPieceAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsJumpableFrom
public static bool IsJumpableFrom(Game game, Coord src, Coord toJump)
{
Coord diff = new Coord() { Row = toJump.Row - src.Row, Col = toJump.Col - src.Col };
Coord toLand = new Coord() { Row = src.Row + diff.Row * 2, Col = src.Col + diff.Col * 2 };
// TODO add out of bounds checking
return game.GetPieceAt(toLand) == BoardSpaceState.None && game.GetPieceAt(toJump) != BoardSpaceState.None;
}
示例2: GameWinner
public static RelativePlayer GameWinner(Game game)
{
var opponentOutOfPieces = game
.QueryPieceLocations
.Select(pieceLoc => pieceLoc.Value)
.Where(GameUtils.IsOpponent)
.Count() < MIN_PIECES;
var friendlyOutOfPieces = game
.QueryPieceLocations
.Select(pieceLoc => pieceLoc.Value)
.Where(GameUtils.IsFriendly)
.Count() < MIN_PIECES;
var opponentInFriendlyEndzone =
GameUtils.IsOpponent(game.GetPieceAt(new Coord() { Row = Game.BOARD_ROW_MAX, Col = Game.ENDZONE_COL_1 })) &&
GameUtils.IsOpponent(game.GetPieceAt(new Coord() { Row = Game.BOARD_ROW_MAX, Col = Game.ENDZONE_COL_2 }));
var friendlyInOpponentEndzone =
GameUtils.IsFriendly(game.GetPieceAt(new Coord() { Row = 0, Col = Game.ENDZONE_COL_1 })) &&
GameUtils.IsFriendly(game.GetPieceAt(new Coord() { Row = 0, Col = Game.ENDZONE_COL_2 }));
return
opponentOutOfPieces ? RelativePlayer.Friendly :
friendlyOutOfPieces ? RelativePlayer.Opponent :
opponentInFriendlyEndzone ? RelativePlayer.Opponent :
friendlyInOpponentEndzone ? RelativePlayer.Friendly :
RelativePlayer.None;
}
示例3: AddPiece
public void AddPiece()
{
Coord coord = new Coord() { Row = 1, Col = 0 };
var piece = BoardSpaceState.FriendlyPieceShort;
Game game = new Game();
game.SetPieceLocation(coord, piece);
Assert.AreEqual(piece, game.GetPieceAt(coord));
}
示例4: IsCompleteMove
public static bool IsCompleteMove(Game game)
{
return
GameUtils.PiecesJumped(game, game.ActiveMoves).Count() == 0 ||
GameUtils.NeighborsOf(game, game.ActiveMoves.Last())
.Where(neighbor =>
GameUtils.IsJumpableFrom(game, game.ActiveMoves.Last(), neighbor)
&& GameUtils.IsOpponent(game.GetPieceAt(neighbor))
&& ! new HashSet<Coord>(GameUtils.SpacesJumped(game, game.ActiveMoves)).Contains(neighbor))
.Count() == 0;
}
示例5: ExecuteMoves_Capture_MovesPieceAwayFromStart
public void ExecuteMoves_Capture_MovesPieceAwayFromStart()
{
Game game = new Game();
game.SetPieceLocation(Coord.Create(0, 0), BoardSpaceState.FriendlyPieceShort);
game.SetPieceLocation(Coord.Create(0, 1), BoardSpaceState.OpponentPieceShort);
game.AddActiveMove(Coord.Create(0, 0));
game.AddActiveMove(Coord.Create(0, 2));
GameController.ExecuteMoves(game);
Assert.AreEqual(game.GetPieceAt(Coord.Create(0, 0)), BoardSpaceState.None);
}
示例6: ExecuteMoves
public static void ExecuteMoves(Game game, bool flipPieceState = false)
{
if (game.ActiveMoves.Count() == 0)
{
return;
}
Func<BoardSpaceState, BoardSpaceState> getPieceForPlayer = boardSpaceState => flipPieceState ? boardSpaceState.TogglePlayer() : boardSpaceState;
if (!(game.ActiveMoves.Count() == 2 && GameUtils.AreNeighbors(game.ActiveMoves.First(), game.ActiveMoves.Last())))
{
// TODO the recepient can't capture anything - perhaps a board flipping issue?
var opponentsLoc =
game.ActiveMoves
.Pairwise()
.Select((moves) => GameUtils.SpaceBetween(moves.Item1, moves.Item2))
.Where(loc => GameUtils.IsOpponent(getPieceForPlayer(game.GetPieceAt(loc))));
// TODO this doesn't actually fire
Debug.Assert(opponentsLoc.Count() > 0, "If we're doing a jump, we should find some pieces to capture.");
foreach (var opponentLoc in opponentsLoc)
{
game.CapturePiece(game.GetPieceAt(opponentLoc));
game.SetPieceLocation(opponentLoc, BoardSpaceState.None);
}
}
GameUtils.MovePiece(game, game.ActiveMoves.First(), game.ActiveMoves.Last());
game.ClearActiveMoves();
game.Winner = GameValidator.GameWinner(game);
game.WaitingOn = game.WaitingOn.Toggle();
}
示例7: IsValidMove
// TODO check that move is within bounds
public static bool IsValidMove(Game game, Coord move, bool flipPieceState = false)
{
if (GameWinner(game) != RelativePlayer.None)
{
return false;
}
var pieceAtMove = game.GetPieceAt(move);
// TODO hacky shit
if (flipPieceState)
{
pieceAtMove = pieceAtMove.TogglePlayer();
}
if (! game.NoActiveMovesExist && pieceAtMove != BoardSpaceState.None)
{
return false;
}
if (game.NoActiveMovesExist)
{
return pieceAtMove == BoardSpaceState.FriendlyPieceShort || pieceAtMove == BoardSpaceState.FriendlyPieceTall;
}
if (GameUtils.AreNeighbors(game.GetMostRecentMove(), move))
{
return game.ActiveMoves.Count() == 1;
}
Coord locationToJump;
var isJumpable = GameUtils.SpaceBetween(move, game.GetMostRecentMove(), out locationToJump);
if (isJumpable)
{
if (game.ActiveMoves.Count() > 1
&& game.ActiveMoves.Pairwise().All(moves => GameUtils.AreNeighbors(moves.Item1, moves.Item2)))
{
return false;
}
var piecesJumped = GameUtils.PiecesJumped(game,
Enumerable.Concat(game.ActiveMoves,
Enumerable.Repeat(move, 1)));
return piecesJumped.All(GameUtils.IsFriendly)
|| piecesJumped.All(GameUtils.IsOpponent)
|| (game.GetPieceAt(game.ActiveMoves.First()) == BoardSpaceState.FriendlyPieceTall
&& game.GetPieceAt(locationToJump) != BoardSpaceState.None);
}
return false;
}
示例8: MovePiece
public static void MovePiece(Game game, Coord src, Coord dest)
{
game.SetPieceLocation(dest, game.GetPieceAt(src));
game.SetPieceLocation(src, BoardSpaceState.None);
}
示例9: ExecuteMoves_Capture_RemovesCapturedPiece
public void ExecuteMoves_Capture_RemovesCapturedPiece()
{
Game game = new Game();
game.SetPieceLocation(Coord.Create(0, 0), BoardSpaceState.FriendlyPieceShort);
game.SetPieceLocation(Coord.Create(0, 1), BoardSpaceState.OpponentPieceShort);
game.AddActiveMove(Coord.Create(0, 0));
game.AddActiveMove(Coord.Create(0, 2));
GameController.ExecuteMoves(game);
Assert.AreEqual(BoardSpaceState.None, game.GetPieceAt(Coord.Create(0, 1)));
Assert.AreEqual(1, game.GetCapturedCount(BoardSpaceState.OpponentPieceShort));
}
示例10: ImplicitNone
public void ImplicitNone()
{
Game game = new Game();
Assert.AreEqual(BoardSpaceState.None, game.GetPieceAt(new Coord() { Row = 0, Col = 0 }));
}
示例11: ExecuteMoves_HandleSingleMove
public void ExecuteMoves_HandleSingleMove()
{
Game game = new Game();
game.SetPieceLocation(Coord.Create(0, 10), BoardSpaceState.FriendlyPieceShort);
game.AddActiveMove(Coord.Create(0, 10));
game.AddActiveMove(Coord.Create(0, 11));
GameController.ExecuteMoves(game);
Assert.AreEqual(BoardSpaceState.None, game.GetPieceAt(Coord.Create(0, 10)));
Assert.AreEqual(BoardSpaceState.FriendlyPieceShort, game.GetPieceAt(Coord.Create(0, 11)));
}