本文整理汇总了C#中BitArray.Or方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Or方法的具体用法?C# BitArray.Or怎么用?C# BitArray.Or使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitArray
的用法示例。
在下文中一共展示了BitArray.Or方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPassable
public static BitArray GetPassable(bool walkInWater = false)
{
var impassible = new BitArray(Bb.Glaciers).Or(Bb.TheirSpawns).Or(Bb.TheirUnits).Or(Bb.OurUnits);
if (!walkInWater)
{
impassible.Or(Bb.Water);
}
var spawning = Bb.OurSpawnSet.Union(Bb.OurPumpSet.Union(Bb.TheirPumpSet).SelectMany(pump => pump.GetPoints())).Where(p => Bb.tileLookup[p].IsSpawning);
return spawning.ToBitArray().Or(impassible).Not();
}
示例2: Or_Operator
public static void Or_Operator(bool[] l, bool[] r, bool[] expected)
{
BitArray left = new BitArray(l);
BitArray right = new BitArray(r);
BitArray actual = left.Or(right);
Assert.Same(left, actual);
Assert.Equal(actual.Length, expected.Length);
for (int i = 0; i < expected.Length; i++)
{
Assert.Equal(expected[i], actual[i]);
}
}
示例3: Or_Invalid
public static void Or_Invalid()
{
BitArray bitArray1 = new BitArray(11, false);
BitArray bitArray2 = new BitArray(6, false);
// Different lengths
Assert.Throws<ArgumentException>(null, () => bitArray1.Or(bitArray2));
Assert.Throws<ArgumentException>(null, () => bitArray2.Or(bitArray1));
Assert.Throws<ArgumentNullException>("value", () => bitArray1.Or(null));
}
示例4: OperatorTest
public static void OperatorTest(Operator op)
{
BitArray bitArray1 = new BitArray(6, false);
BitArray bitArray2 = new BitArray(6, false);
BitArray result;
bitArray1.Set(0, true);
bitArray1.Set(1, true);
bitArray2.Set(1, true);
bitArray2.Set(2, true);
switch (op)
{
case Operator.Xor:
result = bitArray1.Xor(bitArray2);
Assert.Same(bitArray1, result);
Assert.True(result.Get(0));
Assert.False(result.Get(1));
Assert.True(result.Get(2));
Assert.False(result.Get(4));
break;
case Operator.And:
result = bitArray1.And(bitArray2);
Assert.Same(bitArray1, result);
Assert.False(result.Get(0));
Assert.True(result.Get(1));
Assert.False(result.Get(2));
Assert.False(result.Get(4));
break;
case Operator.Or:
result = bitArray1.Or(bitArray2);
Assert.Same(bitArray1, result);
Assert.True(result.Get(0));
Assert.True(result.Get(1));
Assert.True(result.Get(2));
Assert.False(result.Get(4));
break;
}
// Size stress cases.
bitArray1 = new BitArray(0x1000F, false);
bitArray2 = new BitArray(0x1000F, false);
bitArray1.Set(0x10000, true); // The bit for 1 (2^0).
bitArray1.Set(0x10001, true); // The bit for 2 (2^1).
bitArray2.Set(0x10001, true); // The bit for 2 (2^1).
switch (op)
{
case Operator.Xor:
result = bitArray1.Xor(bitArray2);
Assert.Same(bitArray1, result);
Assert.True(result.Get(0x10000));
Assert.False(result.Get(0x10001));
Assert.False(result.Get(0x10002));
Assert.False(result.Get(0x10004));
break;
case Operator.And:
result = bitArray1.And(bitArray2);
Assert.Same(bitArray1, result);
Assert.False(result.Get(0x10000));
Assert.True(result.Get(0x10001));
Assert.False(result.Get(0x10002));
Assert.False(result.Get(0x10004));
break;
case Operator.Or:
result = bitArray1.Or(bitArray2);
Assert.Same(bitArray1, result);
Assert.True(result.Get(0x10000));
Assert.True(result.Get(0x10001));
Assert.False(result.Get(0x10002));
Assert.False(result.Get(0x10004));
break;
}
}
示例5: GetWalkingSteps
public static LinkedList<Point> GetWalkingSteps(Point start, BitArray goals, bool walkInWater = false, bool nearbyOk = false)
{
Bb.ReadBoard();
if (!goals.ToPoints().Any())
{
return null;
}
Point[] starts = { start };
var passable = Solver.GetPassable(true);
var aStarPassable = new BitArray(passable);
aStarPassable.Set(start, true);
if (nearbyOk)
{
aStarPassable.Or(goals);
}
Func<Point, Point, int> cost = (c, n) => (Bb.Water.Get(n) && !walkInWater) ? 10 : 1;
var route = Pather.AStar(starts, p => goals.Get(p), aStarPassable, cost, p => 0);
if (route == null)
{
return null;
}
var steps = new LinkedList<Point>(route);
steps.RemoveFirst();
if (steps.Count > 0 && !passable.Get(steps.Last.Value))
{
steps.RemoveLast();
}
return steps;
}
示例6: runTest
public virtual bool runTest()
{
Console.Error.WriteLine( "Co1551Or.cs runTest() started." );
String strWrite = null;
int iCountErrors = 0;
int iCountTestcases = 0;
BitArray ba2 = null;
BitArray ba3 = null;
BitArray ba4 = null;
ba2 = new BitArray( 6 ,false );
ba3 = new BitArray( 6 ,false );
ba2.Set( 0 ,true );
ba2.Set( 1 ,true );
ba3.Set( 1 ,true );
ba3.Set( 2 ,true );
ba4 = ba2.Or( ba3 );
++iCountTestcases;
if ( ! ba4.Get( 0 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_936hf (Co1551Or.cs)" );
}
++iCountTestcases;
if ( ! ba4.Get( 1 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_894fc (Co1551Or.cs)" );
}
++iCountTestcases;
if ( ! ba4.Get( 2 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_755jd (Co1551Or.cs)" );
}
++iCountTestcases;
if ( ba4.Get( 4 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_667sz (Co1551Or.cs)" );
}
ba2 = new BitArray( 0x1000F ,false );
ba3 = new BitArray( 0x1000F ,false );
ba2.Set( 0x10000 ,true );
ba2.Set( 0x10001 ,true );
ba3.Set( 0x10001 ,true );
ba4 = ba2.Or( ba3 );
++iCountTestcases;
if ( ! ba4.Get( 0x10000 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_534xu (Co1551Or.cs)" );
}
++iCountTestcases;
if ( ! ba4.Get( 0x10001 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_400ki (Co1551Or.cs)" );
}
++iCountTestcases;
if ( ba4.Get( 0x10002 ) )
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_357nl (Co1551Or.cs)" );
}
ba2 = new BitArray( 11 ,false );
ba3 = new BitArray( 6 ,false );
try
{
++iCountTestcases;
ba4 = ba2.Or( ba3 );
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_289wx (Co1551Or.cs)" );
}
catch ( ArgumentException exc ) {}
ba2 = new BitArray( 6 ,false );
ba3 = null;
try
{
++iCountTestcases;
ba4 = ba2.Or( ba3 );
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: find E_112gy (Co1551Or.cs)" );
}
catch ( ArgumentException exc ) {}
if ( iCountErrors == 0 )
{
Console.Error.Write( "BitArray\\Co1551Or.cs: paSs. iCountTestcases==" );
Console.Error.WriteLine( iCountTestcases );
return true;
}
else
{
Console.Error.Write( "Co1551Or iCountErrors==" );
Console.Error.WriteLine( iCountErrors );
Console.Error.WriteLine( "BitArray\\Co1551Or.cs: FAiL!" );
return false;
}
}
示例7: GetConnectedPumpStations
// returns a bitboard of all connected pump stations for the specified player
public static BitArray GetConnectedPumpStations(int player)
{
// get bitboard of all pump stations for specified player
BitArray pumpStations = new BitArray(length, false);
if (player == myID)
{
pumpStations.Or(myPumpStations);
}
else if (player == oppID)
{
pumpStations.Or(oppPumpStations);
}
if (Equal(pumpStations, empty))
{
return empty;
}
// get connected pump stations
BitArray connectedPumpStations = new BitArray(length, false);
BitArray waterAndTrenchTiles = new BitArray(length, false).Or(waterTiles).Or(trenchTiles);
List<int> pumpStationIndeces = GetIndexes(pumpStations);
foreach (int index in pumpStationIndeces)
{
// get current pump station
BitArray currentPumpStation = GetPumpStation(pumpStations, index / height, index % height);
if (Equal(currentPumpStation, empty))
{
continue;
}
// get starting points from current pump station's adjacency bitboard
BitArray currentAdjacency = GetAdjacency(currentPumpStation).And(waterAndTrenchTiles);
if (Equal(currentAdjacency, empty))
{
// remove current pump station from pump stations bitboard, continue
pumpStations.Xor(currentPumpStation);
continue;
}
List<int> startingPoints = GetIndexes(currentAdjacency);
// get path from starting points to nearest connected glacier
foreach (int start in startingPoints)
{
BitArray invalidTiles = new BitArray(length, false).Or(waterTiles).Or(trenchTiles).Or(iceCaps).Xor(full);
List<Node> path = AStar.route(GetX(start), GetY(start), iceCaps, false, invalidTiles);
// if a path exists and ice cap is still producing, add current pump station to connected pump stations bitboard, go to next pump station
if (path.Count != 0)
{
bool validConnected = true;
foreach (Tile tile in BaseAI.tiles)
{
if (tile.X == path[path.Count - 1].x && tile.Y == path[path.Count - 1].y)
{
if (tile.WaterAmount <= 1)
{
validConnected = false;
}
break;
}
}
if (validConnected)
{
connectedPumpStations.Or(currentPumpStation);
break;
}
}
}
// remove current pump station from pump stations bitboard
pumpStations.Xor(currentPumpStation);
}
return connectedPumpStations;
}
示例8: GetAdjacency
// returns the adjacency bitboard for a specified bitboard
public static BitArray GetAdjacency(BitArray bitboard)
{
BitArray adjacency = new BitArray(bitboard).Or(ShiftLeft(bitboard, 1).And(validLeft)).Or(ShiftRight(bitboard, 1).And(validRight));
return adjacency.Or(ShiftLeft(adjacency, height)).Or(ShiftRight(adjacency, height)).Xor(bitboard);
}
示例9: GetPumpStation
// returns a bitboard of a pump station that exists on the specified coordinates,
// or return empty if no pump station exists on the specified coordinates
public static BitArray GetPumpStation(BitArray pumpStations, int x, int y)
{
// check to see if specified unit is on one of our pump stations
BitArray test = new BitArray(length, false).Or(pumpStations);
test.And(position[x][y]);
if (Equal(test, empty))
{
return empty;
}
// create bitboard representing pump station the unit is standing on
BitArray pumpStation = new BitArray(length, false).Or(position[x][y]);
if (x - 1 >= 0)
{
pumpStation.Or(position[x - 1][y]);
if (y - 1 >= 0)
{
pumpStation.Or(position[x - 1][y - 1]);
}
if (y + 1 < height)
{
pumpStation.Or(position[x - 1][y + 1]);
}
}
if (x + 1 < width)
{
pumpStation.Or(position[x + 1][y]);
if (y - 1 >= 0)
{
pumpStation.Or(position[x + 1][y - 1]);
}
if (y + 1 < height)
{
pumpStation.Or(position[x + 1][y + 1]);
}
}
if (y - 1 >= 0)
{
pumpStation.Or(position[x][y - 1]);
}
if (y + 1 < height)
{
pumpStation.Or(position[x][y + 1]);
}
return pumpStation.And(pumpStations);
}
示例10: GetConnectedTrenches
// returns a bitboard of all trenches connected to starting bitboard
public static void GetConnectedTrenches(ref BitArray connectedTrenches, BitArray currentAdjacency, ref BitArray waterAndTrenchTiles)
{
connectedTrenches.Or(currentAdjacency);
List<int> indexes = GetIndexes(currentAdjacency);
foreach (int i in indexes)
{
GetConnectedTrenches(ref connectedTrenches, GetNonDiagonalAdjacency(new BitArray(position[GetX(i)][GetY(i)])).And(waterAndTrenchTiles), ref waterAndTrenchTiles);
}
}