本文整理汇总了C#中Position.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Position.Equals方法的具体用法?C# Position.Equals怎么用?C# Position.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Position
的用法示例。
在下文中一共展示了Position.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInequality
public static void TestInequality()
{
Position position1 = new Position(File.E, Rank.Two);
Position position2 = new Position(File.B, Rank.Five);
Assert.AreNotEqual(position1, position2, "position1 and position2 are equal");
Assert.False(position1.Equals(position2), "position1.Equals(position2) should be false");
Assert.False(position2.Equals(position1), "position2.Equals(position1) should be false");
Assert.True(position1 != position2, "position1 != position2 should be true");
Assert.True(position2 != position1, "position2 != position1 should be true");
Assert.False(position1 == position2, "position1 == position2 should be false");
Assert.False(position2 == position1, "position2 == position1 should be false");
Assert.AreNotEqual(position1.GetHashCode(), position2.GetHashCode(), "Hash codes of position1 and position2 should be different");
Position position3 = new Position(File.E, Rank.Two);
Position position4 = new Position(File.E, Rank.Five);
Assert.AreNotEqual(position3, position4, "position3 and position4 are equal");
Assert.False(position3.Equals(position4), "position3.Equals(position4) should be false");
Assert.False(position3.Equals(position4), "position4.Equals(position3) should be false");
Assert.True(position3 != position4, "position3 != position4 should be true");
Assert.True(position4 != position3, "position4 != position3 should be true");
Assert.False(position3 == position4, "position3 == position4 should be false");
Assert.False(position4 == position3, "position4 == position3 should be false");
Assert.AreNotEqual(position3.GetHashCode(), position4.GetHashCode(), "Hash codes of position3 and position4 should be different");
Position position5 = new Position(File.E, Rank.Two);
Position position6 = new Position(File.B, Rank.Two);
Assert.AreNotEqual(position5, position6, "position5 and position6 are equal");
Assert.False(position5.Equals(position6), "position5.Equals(position6) should be false");
Assert.False(position6.Equals(position5), "position6.Equals(position5) should be false");
Assert.True(position5 != position6, "position5 != position6 should be true");
Assert.True(position6 != position5, "position6 != position5 should be true");
Assert.False(position5 == position6, "position5 == position6 should be false");
Assert.False(position6 == position5, "position6 == position5 should be false");
Assert.AreNotEqual(position5.GetHashCode(), position6.GetHashCode(), "Hash codes of position5 and position6 should be different");
}
示例2: Equals
public void Equals ()
{
var position1 = new Position (78, 167);
var position2 = new Position (78, 167);
Assert.True (position1.Equals (position2));
Assert.False (position2.Equals (null));
Assert.True (position2.Equals (position2));
Assert.False (position2.Equals ("position2"));
}
示例3: MarketOrder
public MarketOrder(Tick t, Position.PositionSide side, double orderSize)
{
Symbol = t.Symbol;
Side = side;
Price = (side.Equals(Position.PositionSide.Long)) ? t.AskClose : t.BidClose;
Size = orderSize;
OrderDate = t.Time;
}
示例4: TestEquals_ObjectNotPosition
public void TestEquals_ObjectNotPosition()
{
Position position = new Position(3, 5);
object notPosition = new object();
bool actual = position.Equals(notPosition);
bool expected = false;
Assert.AreEqual(expected, actual);
}
示例5: TestInequalityNull
public static void TestInequalityNull()
{
Position position1 = new Position(File.E, Rank.One);
Position position2 = null;
Assert.AreNotEqual(position1, position2, "position1 and position2 should not be equal");
Assert.False(position1.Equals(position2), "position1.Equals(position2) should be false");
Assert.True(position1 != position2, "position1 != position2 should be true");
Assert.True(position2 != position1, "position2 != position1 should be true");
Assert.False(position1 == position2, "position1 == position2 should be false");
Assert.False(position2 == position1, "position2 == position1 should be false");
}
示例6: TestEquality
public static void TestEquality()
{
Position position1 = new Position(File.C, Rank.Six);
Position position2 = new Position(File.C, Rank.Six);
Assert.AreEqual(position1, position2, "position1 and position2 are not equal");
Assert.True(position1.Equals(position2), "position1.Equals(position2) should be true");
Assert.True(position2.Equals(position1), "position2.Equals(position1) should be true");
Assert.True(position1 == position2, "position1 == position2 should be true");
Assert.True(position2 == position1, "position2 == position1 should be true");
Assert.False(position1 != position2, "position1 != position2 should be false");
Assert.False(position2 != position1, "position2 != position1 should be false");
Assert.AreEqual(position1.GetHashCode(), position2.GetHashCode(), "Hash codes should be equal");
}
示例7: Equals_WhenYIsDifferent_ShouldReturnFalse
public void Equals_WhenYIsDifferent_ShouldReturnFalse()
{
// Arrange
var x = fixture.Create<int>();
var position1 = new Position(x, 0);
var position2 = new Position(x, 1);
// Act
var result = position1.Equals(position2);
// Assert
Assert.That(result, Is.False);
}
示例8: GenerateObstacle
static void GenerateObstacle()
{
obstaclePosition = new Position(rand.Next(width), rand.Next(height));
while (snakeElements.Contains(obstaclePosition) || obstaclePosition.Equals(foodPosition))
{
obstaclePosition = new Position(rand.Next(width), rand.Next(height));
}
Console.SetCursorPosition(obstaclePosition.col, obstaclePosition.row);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("#");
Console.ForegroundColor = ConsoleColor.Green;
obstacles.Add(obstaclePosition);
}
示例9: CanApply
public bool CanApply(Position from, Position to, IGameState state)
{
if (to.Equals(((ChessState)state).EnPassant))
if (Position.FileDistance(to, from) == 1)
switch (state[from].Player.Order)
{
case 1:
return to.Rank - from.Rank == 1;
case 2:
return from.Rank - to.Rank == 1;
}
return false;
}
示例10: Equals_WhenMembersAreEqual_ShouldReturnTrue
public void Equals_WhenMembersAreEqual_ShouldReturnTrue()
{
// Arrange
var x = fixture.Create<int>();
var y = fixture.Create<int>();
var position1 = new Position(x, y);
var position2 = new Position(x, y);
// Act
var result = position1.Equals(position2);
// Assert
Assert.That(result, Is.True);
}
示例11: MoveCommandRun_ShouldMoveOneUnitInFacingDirection
public void MoveCommandRun_ShouldMoveOneUnitInFacingDirection()
{
// Arrange
Robot testRobot = new Robot();
testRobot.Position = new Position(0, 0, Direction.North);
MoveCommand moveCommand = new MoveCommand();
Position expectedPosition = new Position(0,1,Direction.North);
// Act
bool success = moveCommand.Run(testRobot);
// Assert
Assert.IsTrue(expectedPosition.Equals(testRobot.Position));
}
示例12: RightCommandRun_ShouldChangeDirectionToRight
public void RightCommandRun_ShouldChangeDirectionToRight()
{
// Arrange
Robot testRobot = new Robot();
testRobot.Position = new Position(0, 0, Direction.North);
Position expectedPosition = new Position(0, 0, Direction.East);
// Act
RightCommand rightCommand = new RightCommand();
bool success = rightCommand.Run(testRobot);
// Assert
Assert.IsTrue(expectedPosition.Equals(testRobot.Position));
}
示例13: Main
static void Main()
{
// Changing the console colors
Console.BackgroundColor = ConsoleColor.DarkGreen;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BufferHeight = height;
Console.BufferWidth = width;
// Generating the initial snake elements positions
for (int i = 0; i < 6; i++)
{
snakeElements.Enqueue(new Position(i, 3));
}
GenerateFood();
// Starting game cycle
while (!isDead)
{
// Clearing the last element of the snake after every move
Console.SetCursorPosition(snakeElements.First().col, snakeElements.First().row);
Console.Write(" ");
// Checks for an available key and if there is so changing the snake direction
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.LeftArrow)
{
if (direction != right)
{
direction = left;
}
}
if (key.Key == ConsoleKey.UpArrow)
{
if (direction != down)
{
direction = up;
}
}
if (key.Key == ConsoleKey.RightArrow)
{
if (direction != left)
{
direction = right;
}
}
if (key.Key == ConsoleKey.DownArrow)
{
if (direction != up)
{
direction = down;
}
}
}
// Getting the snake head position and next move position
Position snakeHead = snakeElements.Last();
Position snakeNextPosition = new Position(snakeHead.col + directions[direction].col, snakeHead.row + directions[direction].row);
// getting the conditions wheather the snake is dead or no
isDead =
snakeElements.Contains(snakeNextPosition)
|| obstacles.Contains(snakeNextPosition)
|| snakeNextPosition.col > width - 1
|| snakeNextPosition.col < 0
|| snakeNextPosition.row > height - 1
|| snakeNextPosition.row < 0;
// Checks whether the snake is dead
if (isDead)
{
Console.SetCursorPosition(width / 2 - 5, height / 2);
Console.WriteLine("Game Over");
Environment.Exit(0);
}
// Checks whether the snake has eaten an apple
if (!snakeNextPosition.Equals(foodPosition))
{
snakeElements.Dequeue();
}
else
{
GenerateFood();
GenerateObstacle();
}
// Prints the snake next position
snakeElements.Enqueue(snakeNextPosition);
PrintSnake();
Thread.Sleep(100);
}
}
示例14: MoveFigure
private void MoveFigure(Position oldPos, Position newPos)
{
//changing play window cursor
playWindow.Cursor = Cursors.WaitCursor;
//rock change implementation
if (newPos.Equals(matrix.GetKing(runColor)) && !matrix.FigureAt(matrix.GetKing(runColor)).IsMoved)
{
int dx = oldPos.X - newPos.X;
dx = (dx > 0) ? (1) : (-1);
Position kingPos = new Position(newPos.X + dx * 2, newPos.Y);
Position rockPos = new Position(newPos.X + dx, newPos.Y);
matrix.MoveFigure(newPos, kingPos);
matrix.FigureAt(kingPos).IncreaseSteps();
playWindow.matrix.MoveImage(newPos, kingPos);
matrix.MoveFigure(oldPos, rockPos);
matrix.FigureAt(rockPos).IncreaseSteps();
playWindow.matrix.MoveImage(oldPos, rockPos);
//print message in system log console
playWindow.PrintToConsole("System: ", System.Drawing.Color.Red);
playWindow.PrintToConsoleLn("King-rock change", System.Drawing.Color.Green);
}
else
{ //simple figure move
//print message in system log console
if (runColor == FigureColor.WHITE)
{
playWindow.PrintToConsole("System: ", System.Drawing.Color.Red);
playWindow.PrintToConsoleLn("Player1 moved " + matrix.FigureAt(oldPos).ToString() + " from " +
(char)('A' + oldPos.X) + Convert.ToString(8 - oldPos.Y) + " to " +
(char)('A' + newPos.X) + Convert.ToString(8 - newPos.Y), System.Drawing.Color.FromArgb(64, 128, 255));
}
else
{
playWindow.PrintToConsole("System: ", System.Drawing.Color.Red);
playWindow.PrintToConsoleLn("Player2 moved " + matrix.FigureAt(oldPos).ToString() + " from " +
(char)('A' + oldPos.X) + Convert.ToString(8 - oldPos.Y) + " to " +
(char)('A' + newPos.X) + Convert.ToString(8 - newPos.Y), System.Drawing.Color.FromArgb(128, 64, 255));
}
Figure figure = matrix.FigureAt(oldPos);
matrix.MoveFigure(oldPos, newPos);
playWindow.matrix.MoveImage(oldPos, newPos);
figure.IncreaseSteps();
//checking pawn move gap
if (figure is Pawn)
{
((Pawn)figure).TwoStepState = (Math.Abs(oldPos.Y - newPos.Y) == 2);
//Проверка на замену пешки другой фигурой
if ((runColor == FigureColor.WHITE && newPos.Y == 0) || (runColor == FigureColor.BLACK && newPos.Y == 7))
{
if ((network.type == NetWorkType.SERVER && runColor == FigureColor.WHITE) || (network.type == NetWorkType.CLIENT && runColor == FigureColor.BLACK))
{
FigureChoiceWindow w = new FigureChoiceWindow(playWindow.GetPosOnScreen(newPos), runColor);
w.ShowDialog(playWindow);
matrix.SetFigure(w.Result, newPos);
playWindow.matrix.SetImage(w.Result.image, newPos);
playWindow.ReDraw(true);
}
}
else
{
GetInPass(oldPos, newPos);
((Pawn)matrix.FigureAt(newPos)).NeighborsFigures[1] = matrix.FigureAt(newPos.X + 1, newPos.Y);
((Pawn)matrix.FigureAt(newPos)).NeighborsFigures[0] = matrix.FigureAt(newPos.X - 1, newPos.Y);
}
}
}
//changing color changing
runColor = (runColor == FigureColor.WHITE) ? (FigureColor.BLACK) : (FigureColor.WHITE);
CheckForMate();
playWindow.matrix.ResetAllAttribures();
playWindow.Cursor = Cursors.Default;
playWindow.ReDraw();
}
示例15: DigStairs
/// <summary>
/// Each level requires at least one stair!
/// </summary>
private void DigStairs()
{
/* Dig stairs upwards. */
/* Find a section. */
Position s1 = GetRandomSection();
Position sectionTopLeft1 = Sections[s1.X, s1.Y].TopLeft;
StairsUp = new Position(
(sectionTopLeft1.X + Terminal.RandByte((byte) (RoomWidth(s1) - 1)) + 1),
(sectionTopLeft1.Y + Terminal.RandByte((byte) (RoomHeight(s1) - 1)) + 1)
);
/* Dig stairs downwards. */
if (IsBottom) return;
/* Find a section. */
Position s2 = GetRandomSection();
Position position;
/* Find a good location. */
do
{
Position sectionTopLeft2 = Sections[s2.X, s2.Y].TopLeft;
position = new Position(
sectionTopLeft2.X + Terminal.RandByte((byte) (RoomWidth(s2) - 1)) + 1,
sectionTopLeft2.Y + Terminal.RandByte((byte) (RoomHeight(s2) - 1)) + 1);
} while (!IsTop && position.Equals(StairsUp));
/* Place the stairway. */
StairsDown = position;
}