//Negamax sa evaluacijom Move GetBestMoveNegamaxEval(Board b, int alpha, int beta, int depth) { for (int x = 0; x < 7; x++) { if (!b.CantPlay(moveOrder[x]) && b.IsWinningMove(moveOrder[x])) { return(new Move(moveOrder[x], (10000 - b.Moves) / 2, true)); } } if (depth == 0) { return(new Move(b.EvaluateThreats())); } int maxScore = (9998 - b.Moves) / 2; TableData entry = transpTable.Return(b.Current, b.Mask); if (entry != null) { int val = Convert.ToInt32(entry.value); if (val < -3000 || val > 3000 || Convert.ToInt32(entry.depth) >= depth) { maxScore = val; } } if (beta > maxScore) { beta = maxScore; if (alpha >= beta) { return(new Move(beta)); } } Move bestMove = new Move(alpha); for (int x = 0; x < 7; x++) { if (!b.CantPlay(moveOrder[x])) { Move m = b.MakeMove(moveOrder[x]); m.Score = -GetBestMoveNegamaxEval(b, -beta, -alpha, depth - 1).Score; b.RemoveMove(m); if (m.Score >= beta) { return(m); } if (m.Score > bestMove.Score) { alpha = m.Score; bestMove = m; } } } transpTable.Add(b.Current, b.Mask, Convert.ToInt16(bestMove.Score), Convert.ToByte(depth)); //ovi castovi su safe za opsege koje koristimo return(bestMove); }
public static TranspositionTable Deserialize() { TranspositionTable newTable = new TranspositionTable(); try { using (BinaryReader br = new BinaryReader(new FileStream("table.bin", FileMode.Open))) { while (true) //posto ne znamo koliko ce puta da procita, kada dodje do kraja streama, baci exception EndOfStream { newTable.Add(br.ReadUInt64(), br.ReadUInt64(), br.ReadInt16(), br.ReadByte()); } } } catch (EndOfStreamException e) { Console.WriteLine(e.Message); return(newTable); } catch (Exception e) { Console.WriteLine(e.Message); return(new TranspositionTable()); } }