本文整理汇总了C#中Portfish.Position类的典型用法代码示例。如果您正苦于以下问题:C# Position类的具体用法?C# Position怎么用?C# Position使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Position类属于Portfish命名空间,在下文中一共展示了Position类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: extract_pv_from_tt
/// RootMove::extract_pv_from_tt() builds a PV by adding moves from the TT table.
/// We consider also failing high nodes and not only BOUND_EXACT nodes so to
/// allow to always have a ponder move even when we fail high at root, and a
/// long PV to print that is important for position analysis.
internal void extract_pv_from_tt(Position pos)
{
StateInfoArray sia = StateInfoArrayBroker.GetObject();
int stPos = 0;
TTEntry tte;
int ply = 1;
Move m = pv[0];
Debug.Assert(m != MoveC.MOVE_NONE && pos.is_pseudo_legal(m));
pv.Clear();
pv.Add(m);
pos.do_move(m, sia.state[stPos++]);
UInt32 ttePos = 0;
while (TT.probe(pos.key(), ref ttePos, out tte)
&& (m = tte.move()) != MoveC.MOVE_NONE // Local copy, TT entry could change
&& pos.is_pseudo_legal(m)
&& pos.pl_move_is_legal(m, pos.pinned_pieces())
&& ply < Constants.MAX_PLY
&& (!pos.is_draw(false) || ply < 2))
{
pv.Add(m);
pos.do_move(m, sia.state[stPos++]);
ply++;
}
pv.Add(MoveC.MOVE_NONE);
do pos.undo_move(pv[--ply]); while (ply != 0);
StateInfoArrayBroker.Free();
}
示例2: scale_factor_BLACK
internal ScaleFactor scale_factor_BLACK(Position pos)
{
if (scalingFunctionBLACK == null)
return (factorBLACK);
ScaleFactor sf = scalingFunctionBLACK(ColorC.BLACK, pos);
return sf == ScaleFactorC.SCALE_FACTOR_NONE ? factorBLACK : sf;
}
示例3: scale_factor_WHITE
internal ScaleFactor scale_factor_WHITE(Position pos)
{
if (scalingFunctionWHITE == null)
return factorWHITE;
ScaleFactor sf = scalingFunctionWHITE(ColorC.WHITE, pos);
return sf == ScaleFactorC.SCALE_FACTOR_NONE ? factorWHITE : sf;
}
示例4: generate_castle
private static void generate_castle(
int Side,
bool Checks,
Position pos,
MoveStack[] ms,
ref int mpos,
int us)
{
if (pos.castle_impeded(us, Side) || (pos.can_castle_CR(Utils.make_castle_right(us, Side)) == 0))
{
return;
}
// After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess.
var kfrom = pos.king_square(us);
var rfrom = pos.castle_rook_square(us, Side);
var kto = Utils.relative_square(us, Side == CastlingSideC.KING_SIDE ? SquareC.SQ_G1 : SquareC.SQ_C1);
var enemies = pos.pieces_C(us ^ 1);
Debug.Assert(!pos.in_check());
int K = pos.chess960 ? kto > kfrom ? -1 : 1 : Side == CastlingSideC.KING_SIDE ? -1 : 1;
for (Square s = kto; s != kfrom; s += (Square)K)
{
if ((pos.attackers_to(s) & enemies) != 0)
{
return;
}
}
// Because we generate only legal castling moves we need to verify that
// when moving the castling rook we do not discover some hidden checker.
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
if (pos.chess960 && ((pos.attackers_to(kto, Utils.xor_bit(pos.occupied_squares, rfrom)) & enemies) != 0))
{
return;
}
var m = Utils.make(kfrom, rfrom, MoveTypeC.CASTLING);
if (Checks)
{
var ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
var givesCheck = pos.move_gives_check(m, ci);
CheckInfoBroker.Free();
if (!givesCheck)
{
return;
}
}
ms[mpos++].move = m;
}
示例5: scale_factor_BLACK
internal int scale_factor_BLACK(Position pos)
{
if (this.scalingFunctionBLACK == null)
{
return (this.factorBLACK);
}
var sf = this.scalingFunctionBLACK(ColorC.BLACK, pos);
return sf == ScaleFactorC.SCALE_FACTOR_NONE ? this.factorBLACK : sf;
}
示例6: scale_factor_WHITE
internal int scale_factor_WHITE(Position pos)
{
if (this.scalingFunctionWHITE == null)
{
return this.factorWHITE;
}
var sf = this.scalingFunctionWHITE(ColorC.WHITE, pos);
return sf == ScaleFactorC.SCALE_FACTOR_NONE ? this.factorWHITE : sf;
}
示例7: Run
public void Run(object arguments)
{
string[] args = (string[])arguments;
Plug.Write(Utils.engine_info());
Plug.Write(Constants.endl);
CheckInfoBroker.init();
EvalInfoBroker.init();
SwapListBroker.init();
MovesSearchedBroker.init();
PositionBroker.init();
StateInfoArrayBroker.init();
MListBroker.init();
LoopStackBroker.init();
MovePickerBroker.init();
StateInfoBroker.init();
Utils.init();
#if WINDOWS_RT
#else
Book.init();
#endif
Position.init();
KPKPosition.init();
Endgame.init();
Search.init();
Evaluate.init();
Threads.init();
// .Net warmup sequence
Plug.IsWarmup = true;
Position pos = new Position(Uci.StartFEN, false, Threads.main_thread());
Stack<string> stack = Utils.CreateStack("go depth 7");
Uci.go(pos, stack);
Threads.wait_for_search_finished();
Plug.IsWarmup = false;
StringBuilder sb = new StringBuilder();
for (int i = 1; i < args.Length; i++)
{
sb.Append(args[i]).Append(" ");
}
Uci.uci_loop(sb.ToString());
Threads.exit();
}
示例8: CreateCheckInfo
internal void CreateCheckInfo(Position pos)
{
Color them = pos.sideToMove ^ 1;
ksq = pos.pieceList[them][PieceTypeC.KING][0];
pinned = pos.pinned_pieces();
dcCandidates = pos.discovered_check_candidates();
checkSq[PieceTypeC.PAWN] = Utils.StepAttacksBB[((them << 3) | PieceTypeC.PAWN)][ksq];
checkSq[PieceTypeC.KNIGHT] = Utils.StepAttacksBB_KNIGHT[ksq];
#if X64
checkSq[PieceTypeC.BISHOP] = Utils.BAttacks[ksq][(((pos.occupied_squares & Utils.BMasks[ksq]) * Utils.BMagics[ksq]) >> Utils.BShifts[ksq])];
checkSq[PieceTypeC.ROOK] = Utils.RAttacks[ksq][(((pos.occupied_squares & Utils.RMasks[ksq]) * Utils.RMagics[ksq]) >> Utils.RShifts[ksq])];
#else
checkSq[PieceTypeC.BISHOP] = pos.attacks_from_BISHOP(ksq);
checkSq[PieceTypeC.ROOK] = pos.attacks_from_ROOK(ksq);
#endif
checkSq[PieceTypeC.QUEEN] = checkSq[PieceTypeC.BISHOP] | checkSq[PieceTypeC.ROOK];
checkSq[PieceTypeC.KING] = 0;
}
示例9: generate_castle
private static void generate_castle(CastlingSide Side, bool OnlyChecks, Position pos, MoveStack[] ms, ref int mpos, Color us)
{
if (pos.castle_impeded(us, Side) || (pos.can_castle_CR(Utils.make_castle_right(us, Side))==0) )
return;
// After castling, the rook and king final positions are the same in Chess960
// as they would be in standard chess.
Square kfrom = pos.king_square(us);
Square rfrom = pos.castle_rook_square(us, Side);
Square kto = Utils.relative_square(us, Side == CastlingSideC.KING_SIDE ? SquareC.SQ_G1 : SquareC.SQ_C1);
Bitboard enemies = pos.pieces_C(us ^ 1);
Debug.Assert(!pos.in_check());
for (Square s = Math.Min(kfrom, kto), e = Math.Max(kfrom, kto); s <= e; s++)
if (s != kfrom // We are not in check
&& ((pos.attackers_to(s) & enemies) != 0))
return;
// Because we generate only legal castling moves we need to verify that
// when moving the castling rook we do not discover some hidden checker.
// For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.
if (pos.chess960
&& ((pos.attackers_to(kto, Utils.xor_bit(pos.occupied_squares, rfrom)) & enemies) != 0))
return;
Move m = Utils.make_castle(kfrom, rfrom);
if (OnlyChecks)
{
CheckInfo ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
bool givesCheck = pos.move_gives_check(m, ci);
CheckInfoBroker.Free();
if (!givesCheck) return;
}
ms[mpos++].move = m;
}
示例10: go
internal static int SetupStatePos = 0; // *SetupState = StateRingBuf;
#endregion Fields
#region Methods
// go() is called when engine receives the "go" UCI command. The function sets
// the thinking time and other parameters from the input string, and then starts
// the main searching thread.
internal static void go(Position pos, Stack<string> stack)
{
string token = string.Empty;
LimitsType limits = new LimitsType();
List<Move> searchMoves = new List<Phase>();
while (stack.Count > 0)
{
token = stack.Pop();
if (token == "wtime")
limits.time[ColorC.WHITE] = int.Parse(stack.Pop());
else if (token == "btime")
limits.time[ColorC.BLACK] = int.Parse(stack.Pop());
else if (token == "winc")
limits.inc[ColorC.WHITE] = int.Parse(stack.Pop());
else if (token == "binc")
limits.inc[ColorC.BLACK] = int.Parse(stack.Pop());
else if (token == "movestogo")
limits.movesToGo = int.Parse(stack.Pop());
else if (token == "depth")
limits.depth = int.Parse(stack.Pop());
else if (token == "nodes")
limits.nodes = int.Parse(stack.Pop());
else if (token == "movetime")
limits.movetime = int.Parse(stack.Pop());
else if (token == "infinite")
limits.infinite = 1;
else if (token == "ponder")
limits.ponder = true;
else if (token == "searchmoves")
while ((token = stack.Pop()) != null)
{
searchMoves.Add(Utils.move_from_uci(pos, token));
}
}
Threads.start_searching(pos, limits, searchMoves);
}
示例11: evaluate_pawns
/// PawnTable::evaluate_pawns() evaluates each pawn of the given color
internal static Score evaluate_pawns(Color Us, Position pos, Bitboard ourPawns, Bitboard theirPawns, PawnEntry e)
{
Color Them = (Us == ColorC.WHITE ? ColorC.BLACK : ColorC.WHITE);
Bitboard b;
Square s;
File f;
Rank r;
bool passed, isolated, doubled, opposed, chain, backward, candidate;
Score value = ScoreC.SCORE_ZERO;
Square[] pl = pos.pieceList[Us][PieceTypeC.PAWN];
int plPos = 0;
// Loop through all pawns of the current color and score each pawn
while ((s = pl[plPos++]) != SquareC.SQ_NONE)
{
Debug.Assert(pos.piece_on(s) == Utils.make_piece(Us, PieceTypeC.PAWN));
f = (s & 7);
r = (s >> 3);
// This file cannot be half open
if (Us == ColorC.WHITE)
{
e.halfOpenFilesWHITE &= ~(1 << f);
}
else
{
e.halfOpenFilesBLACK &= ~(1 << f);
}
// Our rank plus previous one. Used for chain detection
b = Utils.RankBB[r] | Utils.RankBB[Us == ColorC.WHITE ? r - 1 : r + 1];
// Flag the pawn as passed, isolated, doubled or member of a pawn
// chain (but not the backward one).
chain = (ourPawns & Utils.AdjacentFilesBB[f] & b) != 0;
isolated = (ourPawns & Utils.AdjacentFilesBB[f]) == 0;
doubled = (ourPawns & Utils.ForwardBB[Us][s]) != 0;
opposed = (theirPawns & Utils.ForwardBB[Us][s]) != 0;
passed = (theirPawns & Utils.PassedPawnMask[Us][s]) == 0;
// Test for backward pawn
backward = false;
// If the pawn is passed, isolated, or member of a pawn chain it cannot
// be backward. If there are friendly pawns behind on adjacent files
// or if can capture an enemy pawn it cannot be backward either.
if (!(passed | isolated | chain)
&& (((ourPawns & Utils.AttackSpanMask[Them][s])) == 0)
&& ((((Utils.StepAttacksBB[((Us << 3) | PieceTypeC.PAWN)][s]) & theirPawns)) == 0))
{
// We now know that there are no friendly pawns beside or behind this
// pawn on adjacent files. We now check whether the pawn is
// backward by looking in the forward direction on the adjacent
// files, and seeing whether we meet a friendly or an enemy pawn first.
b = Utils.StepAttacksBB[((Us << 3) | PieceTypeC.PAWN)][s];
// Note that we are sure to find something because pawn is not passed
// nor isolated, so loop is potentially infinite, but it isn't.
while ((b & (ourPawns | theirPawns)) == 0)
{
if (Us == ColorC.WHITE) { b <<= 8; } else { b >>= 8; }
}
// The friendly pawn needs to be at least two ranks closer than the
// enemy pawn in order to help the potentially backward pawn advance.
backward = (((b | (Us == ColorC.WHITE ? b << 8 : b >> 8)) & theirPawns) != 0);
}
Debug.Assert(opposed | passed | (((Utils.AttackSpanMask[Us][s] & theirPawns)) != 0));
// A not passed pawn is a candidate to become passed if it is free to
// advance and if the number of friendly pawns beside or behind this
// pawn on adjacent files is higher or equal than the number of
// enemy pawns in the forward direction on the adjacent files.
candidate = !(opposed | passed | backward | isolated)
&& (b = Utils.AttackSpanMask[Them][s + (Us == ColorC.WHITE ? SquareC.DELTA_N : SquareC.DELTA_S)] & ourPawns) != 0
&& Bitcount.popcount_1s_Max15(b) >= Bitcount.popcount_1s_Max15(Utils.AttackSpanMask[Us][s] & theirPawns);
// Passed pawns will be properly scored in evaluation because we need
// full attack info to evaluate passed pawns. Only the frontmost passed
// pawn on each file is considered a true passed pawn.
if (passed && !doubled)
{
if (Us == ColorC.WHITE)
{
e.passedPawnsWHITE |= Utils.SquareBB[s];
}
else
{
e.passedPawnsBLACK |= Utils.SquareBB[s];
}
}
// Score this pawn
if (isolated)
value -= IsolatedPawnPenalty[opposed ? 1 : 0][f];
//.........这里部分代码省略.........
示例12: probe
/// PawnTable::pawn_info() takes a position object as input, computes
/// a PawnInfo object, and returns a pointer to it. The result is also stored
/// in an hash table, so we don't have to recompute everything when the same
/// pawn structure occurs again.
internal void probe(Position pos, out PawnEntry e)
{
Key key = pos.pawn_key();
e = entries[((UInt32)key) & Constants.PawnTableMask];
// If pi.key matches the position's pawn hash key, it means that we
// have analysed this pawn structure before, and we can simply return
// the information we found the last time instead of recomputing it.
if (e.key == key) return;
// Initialize PawnInfo entry
e.key = key;
e.passedPawnsWHITE = e.passedPawnsBLACK = 0;
e.kingSquaresWHITE = e.kingSquaresBLACK = SquareC.SQ_NONE;
e.halfOpenFilesWHITE = e.halfOpenFilesBLACK = 0xFF;
// Calculate pawn attacks
Bitboard wPawns = pos.pieces_PTC(PieceTypeC.PAWN, ColorC.WHITE);
Bitboard bPawns = pos.pieces_PTC(PieceTypeC.PAWN, ColorC.BLACK);
e.pawnAttacksWHITE = ((wPawns & ~Constants.FileHBB) << 9) | ((wPawns & ~Constants.FileABB) << 7);
e.pawnAttacksBLACK = ((bPawns & ~Constants.FileHBB) >> 7) | ((bPawns & ~Constants.FileABB) >> 9);
// Evaluate pawns for both colors and weight the result
e.value = evaluate_pawns(ColorC.WHITE, pos, wPawns, bPawns, e)
- evaluate_pawns(ColorC.BLACK, pos, bPawns, wPawns, e);
e.value = Utils.apply_weight(e.value, PawnStructureWeight);
return;
}
示例13: update_safety_BLACK
internal Score update_safety_BLACK(Position pos, Square ksq)
{
kingSquaresBLACK = ksq;
castleRightsBLACK = pos.st.castleRights & CastleRightC.BLACK_ANY;
if (((ksq >> 3) ^ (ColorC.BLACK * 7)) > RankC.RANK_4)
return kingSafetyBLACK = ScoreC.SCORE_ZERO;
Value bonus = shelter_storm(ColorC.BLACK, pos, ksq);
// If we can castle use the bonus after the castle if is bigger
if ((pos.st.castleRights & CastleRightC.BLACK_OO) != 0)
bonus = Math.Max(bonus, shelter_storm(ColorC.BLACK, pos, (SquareC.SQ_G1 ^ (ColorC.BLACK * 56))));
if ((pos.st.castleRights & CastleRightC.BLACK_OOO) != 0)
bonus = Math.Max(bonus, shelter_storm(ColorC.BLACK, pos, (SquareC.SQ_C1 ^ (ColorC.BLACK * 56))));
return kingSafetyBLACK = (bonus << 16);
}
示例14: shelter_storm
/// PawnEntry::shelter_storm() calculates shelter and storm penalties for the file
/// the king is on, as well as the two adjacent files.
internal static Value shelter_storm(Color Us, Position pos, Square ksq)
{
Color Them = (Us == ColorC.WHITE ? ColorC.BLACK : ColorC.WHITE);
Value safety = PawnTable.MaxSafetyBonus;
Bitboard b = pos.byTypeBB[PieceTypeC.PAWN] & (Utils.InFrontBB[Us][ksq >> 3] | Utils.RankBB[ksq >> 3]);
Bitboard ourPawns = b & pos.byColorBB[Us] & ~Utils.RankBB[ksq >> 3];
Bitboard theirPawns = b & pos.byColorBB[Them];
Rank rkUs, rkThem;
File kf = ksq & 7;
kf = (kf == FileC.FILE_A) ? kf + 1 : ((kf == FileC.FILE_H) ? kf - 1 : kf);
for (int f = kf - 1; f <= kf + 1; f++)
{
// Shelter penalty is higher for the pawn in front of the king
b = ourPawns & Utils.FileBB[f];
rkUs = (b != 0) ? ((Us == ColorC.WHITE ? Utils.first_1(b) : (Utils.last_1(b) ^ 56)) >> 3) : RankC.RANK_1;
safety -= PawnTable.ShelterWeakness[f != kf ? 1 : 0][rkUs];
// Storm danger is smaller if enemy pawn is blocked
b = theirPawns & Utils.FileBB[f];
rkThem = (b != 0) ? ((Us == ColorC.WHITE ? Utils.first_1(b) : (Utils.last_1(b) ^ 56)) >> 3) : RankC.RANK_1;
safety -= PawnTable.StormDanger[rkThem == rkUs + 1 ? 1 : 0][rkThem];
}
return safety;
}
示例15: move_to_san
/// move_to_san() takes a position and a legal Move as input and returns its
/// short algebraic notation representation.
internal static string move_to_san(Position pos, int m)
{
if (m == MoveC.MOVE_NONE)
{
return "(none)";
}
if (m == MoveC.MOVE_NULL)
{
return "(null)";
}
Debug.Assert(pos.move_is_legal(m));
Bitboard others, b;
Color us = pos.sideToMove;
var san = new StringBuilder();
Square from = from_sq(m);
Square to = to_sq(m);
Piece pc = pos.piece_on(from);
PieceType pt = type_of(pc);
if (type_of_move(m) == MoveTypeC.CASTLING)
{
san.Append(to > from ? "O-O" : "O-O-O");
}
else
{
if (pt != PieceTypeC.PAWN)
{
san.Append(PieceToChar[ColorC.WHITE][pt]); // Upper case
// Disambiguation if we have more then one piece of type 'pt' that can
// reach 'to' with a legal move.
others = b = (pos.attacks_from_PS(pc, to) & pos.pieces_PTC(pt, us)) ^ (ulong)from;
while (others != 0)
{
Move move = make_move(pop_lsb(ref b), to);
if (!pos.pl_move_is_legal(move, pos.pinned_pieces()))
{
others ^= (ulong)from_sq(move);
}
}
if (others != 0)
{
if ((others & file_bb_S(from)) == 0)
{
san.Append(file_to_char(file_of(from)));
}
else if ((others & rank_bb_S(from)) == 0)
{
san.Append(rank_to_char(rank_of(from)));
}
else
{
san.Append(square_to_string(from));
}
}
}
else if (pos.is_capture(m))
{
san.Append(file_to_char(file_of(from)));
}
if (pos.is_capture(m))
{
san.Append('x');
}
san.Append(square_to_string(to));
if (type_of_move(m) == MoveTypeC.PROMOTION)
{
san.Append('=');
san.Append(PieceToChar[ColorC.WHITE][promotion_type(m)]);
}
}
var ci = CheckInfoBroker.GetObject();
ci.CreateCheckInfo(pos);
if (pos.move_gives_check(m, ci))
{
var st = new StateInfo();
pos.do_move(m, st);
var mlist = MListBroker.GetObject();
mlist.pos = 0;
Movegen.generate_legal(pos, mlist.moves, ref mlist.pos);
san.Append(mlist.pos > 0 ? "+" : "#");
MListBroker.Free();
pos.undo_move(m);
}
CheckInfoBroker.Free();
return san.ToString();
}