public StudyAlgorithm(Game game) : base(game) { BasicMoveFinder = new BasicMoveFinder(game); SwapMoveFinder = new SwapMoveFinder(game); CompositeSinglePileMoveFinder = new CompositeSinglePileMoveFinder(game); ScoreCalculator = new ScoreCalculator(game); }
public SearchAlgorithm(Game game) : base(game) { BasicMoveFinder = new BasicMoveFinder(game); SwapMoveFinder = new SwapMoveFinder(game); SearchMoveFinder = new SearchMoveFinder(game); ScoreCalculator = new ScoreCalculator(game); }
public MoveProcessor(Game game) : base(game) { HoldingMoveStack = new FastList<Move>(); MoveStack = new FastList<Move>(); SpacesMoveStack = new FastList<Move>(); Spaces = new FastList<int>(); }
public SpiderViewModel(Game game) { supportedVariations = new Variation[] { Variation.Spider1, Variation.Spider2, Variation.Spider4, Variation.Spiderette1, Variation.Spiderette2, Variation.Spiderette4, }; supportedAlgorithms = new AlgorithmType[] { AlgorithmType.Study, AlgorithmType.Search, }; Variation = Variation.Spider2; Variations = new ObservableCollection<VariationViewModel>(); AlgorithmType = AlgorithmType.Search; Algorithms = new ObservableCollection<AlgorithmViewModel>(); checkPoints = new List<int>(); NewCommand = new RelayCommand(New); ExitCommand = new RelayCommand(Exit); CopyCommand = new RelayCommand(Copy, CanCopy); PasteCommand = new RelayCommand(Paste, CanPaste); UndoCommand = new RelayCommand(Undo, CanUndo); RedoCommand = new RelayCommand(Redo, CanRedo); DealCommand = new RelayCommand(Deal, CanDeal); MoveCommand = new RelayCommand(Move, CanMove); MoveSelectCommand = new RelayCommand<CardViewModel>(MoveSelect, CanMoveSelect); AutoSelectCommand = new RelayCommand<CardViewModel>(AutoSelect, CanAutoSelect); SetVariationCommand = new RelayCommand<VariationViewModel>(SetVariation); SetAlgorithmCommand = new RelayCommand<AlgorithmViewModel>(SetAlgorithm); if (IsInDesignMode) { Game = new Game(sampleData, AlgorithmType); } else if (game == null) { Game = new Game(Variation, AlgorithmType); } else { Game = game; } Tableau = new TableauViewModel(this); RefreshVariations(); RefreshAlgorithms(); ResetUndoAndRefresh(); }
public CompositeSinglePileMoveFinder(Game game) : base(game) { UncoveringMoves = new MoveList(); OneRunPiles = new PileList(); Used = new PileList(); Roots = new PileList(); WorkingTableau = new Tableau(); HoldingStack = new HoldingStack(); SupplementaryMoves = new MoveList(); MoveStack = new FastList<Move>(); }
public SearchMoveFinder(Game game) : base(game) { UseDepthFirst = false; WorkingTableau = new Tableau(); TranspositionTable = new HashSet<int>(); MoveStack = new MoveList(); Moves = new MoveList(); MaxDepth = 20; MaxNodes = 10000; MoveAllocator = new ListAllocator<Move>(false); NodeAllocator = new ListAllocator<Node>(true); }
public Player() { Game game = new Game(); TraceStartFinish = game.TraceStartFinish; TraceDeals = game.TraceDeals; TraceMoves = game.TraceMoves; TraceSearch = game.TraceSearch; ComplexMoves = game.ComplexMoves; ShowResults = false; NumberOfGames = 100000; Variation = Variation.Spider2; AlgorithmType = AlgorithmType.Study; Seed = 0; NumberOfThreads = 0; gameQueue = new ConcurrentQueue<Game>(); }
public Game(Game other) : this() { FromGame(other); }
public void FromGame(Game other) { Initialize(); TableauInputOutput.FromTableau(other.Tableau); Variation = Tableau.Variation; Algorithm.PrepareToPlay(); }
public static void PrintSideBySide(Game game1, Game game2) { Utils.PrintSideBySide(game1.Tableau, game2.Tableau); }
private void PrintCandidates(Game game) { int count = 0; foreach (ComplexMove move in game.ComplexCandidates) { Utils.WriteLine("move[{0}] = {1}", count, move.ScoreMove); foreach (Move subMove in move.SupplementaryMoves) { Utils.WriteLine(" supplementary: {0}", subMove); } foreach (Move holdingMove in move.HoldingList) { Utils.WriteLine(" holding: {0}", holdingMove); } count++; } }
private void SetVariation(VariationViewModel variation) { Variation = variation.Value; Game = new Game(Variation, AlgorithmType); RefreshVariations(); ResetUndoAndRefresh(); }
private void CheckMoveSucceeds(string initial, string expected) { // Check that the only available move is made. game = new Game(initial); game.Diagnostics = true; Assert.True(game.MakeMove()); string actual = TrimAll(game.ToAsciiString()); CheckResults(initial, expected, actual); }
private void New() { Game = new Game(Variation, AlgorithmType); Game.Start(); ResetUndoAndRefresh(); }
private void SetCoefficients() { Game game = new Game(Variation, AlgorithmType); double[] coefficients = game.Coefficients; InitialCoefficients = new List<double>(coefficients).ToArray(); Coefficients = new List<double>(coefficients).ToArray(); }
private void ReleaseGame(Game game) { gameQueue.Enqueue(game); }
private void ProcessResult(Game game) { if (game.Won) { Interlocked.Increment(ref won); } if (game.Tableau.DiscardPiles.Count > 0) { Interlocked.Increment(ref discards); } Interlocked.Increment(ref played); Interlocked.Add(ref moves, game.Tableau.Moves.Count); if (game.Won) { Interlocked.Add(ref movesWon, game.Tableau.Moves.Count); } else { Interlocked.Add(ref movesLost, game.Tableau.Moves.Count); } Results[game.Seed - Seed] = game.Won; Instances[game.Seed - Seed] = game.Instance; }
private Game PlayOneGame(Game game, int seed) { game.TraceStartFinish = TraceStartFinish; game.TraceDeals = TraceDeals; game.TraceMoves = TraceMoves; game.TraceSearch = TraceSearch; game.ComplexMoves = ComplexMoves; game.AlgorithmType = AlgorithmType; game.Diagnostics = Diagnostics; game.Interactive = Interactive; game.Variation = Variation; game.Coefficients = Coefficients; game.Seed = seed; if (Profile) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); game.Play(); long elapsed = stopwatch.ElapsedMilliseconds; Console.WriteLine("seed = {0,6}, elapsed = {1,6}", game.Seed, elapsed); } else { game.Play(); } ProcessResult(game); return game; }
private Game GetGame() { Game game; if (gameQueue.TryDequeue(out game)) { return game; } game = new Game(); game.Instance = nextInstance++; return game; }
public void PlayOneSet() { played = 0; won = 0; discards = 0; moves = 0; movesWon = 0; movesLost = 0; nextInstance = 0; Results = new bool[NumberOfGames]; Instances = new int[NumberOfGames]; int threads = NumberOfThreads; if (threads == -1) { threads = Environment.ProcessorCount; } if (Debugger.IsAttached || Interactive) { threads = 1; } if (threads == 1) { Game game = new Game(); game.Instance = nextInstance; for (int i = 0; i < NumberOfGames; i++) { PlayOneGame(game, Seed + i); } } else if (threads == 0) { Parallel.For<Game>( 0, NumberOfGames, () => GetGame(), (i, loop, game) => PlayOneGame(game, Seed + i), game => ReleaseGame(game) ); } else { using (Semaphore semaphore = new Semaphore(threads, threads)) { WaitCallback callback = state => { Game game = GetGame(); PlayOneGame(game, (int)state); ReleaseGame(game); semaphore.Release(); }; for (int i = 0; i < NumberOfGames; i++) { // Wait for a processor to become available. semaphore.WaitOne(); // Queue the work item to a thread. ThreadPool.QueueUserWorkItem(callback, Seed + i); } // Allow all threads to finish. for (int i = 0; i < threads; i++) { semaphore.WaitOne(); } } } }
public Game(Game other, AlgorithmType algorithmType) : this() { AlgorithmType = algorithmType; FromGame(other); }
private void CheckUndo(string initial, string expected, string action) { // Check that the only available move is made. game = new Game(initial); game.Diagnostics = true; int checkPoint = game.Tableau.CheckPoint; if (action == "Move") { Assert.True(game.MakeMove()); } else if (action == "Deal") { game.Tableau.Deal(); } else { throw new Exception("unknown action: " + action); } string actual = TrimAll(game.ToAsciiString()); CheckResults(initial, expected, actual); game.Tableau.Revert(checkPoint); string undone = TrimAll(game.ToAsciiString()); CheckResults(initial, initial, undone); }
public SwapMoveFinder(Game game) : base(game) { CardMap = new CardMap(); Used = new FastList<int>(); }
public BasicMoveFinder(Game game) : base(game) { }
private void Paste() { var data = Clipboard.GetData(DataFormats.Text) as string; try { Game = new Game(data, AlgorithmType); } catch (Exception e) { Utils.WriteLine("Exception: {0}", e.Message); } ResetUndoAndRefresh(); }
private void CheckSearchSucceeds(string data1, string data2) { string initial = data1; game = new Game(initial, AlgorithmType.Search); game.Diagnostics = true; Assert.True(game.MakeMove()); string expected = new Game(data2).ToAsciiString(); string actual = game.ToAsciiString(); if (expected != actual) { Print(new Game(initial)); PrintSearch(); Game.PrintSideBySide(new Game(expected), game); Utils.WriteLine("expected: {0}", expected); Utils.WriteLine("actual: {0}", actual); } Assert.Equal(expected, actual); }
private void SetAlgorithm(AlgorithmViewModel algorithm) { AlgorithmType = algorithm.Value; Game = new Game(Variation, AlgorithmType); RefreshAlgorithms(); ResetUndoAndRefresh(); }
public static void Print(Game game) { if (game == null) { return; } Utils.ColorizeToConsole(game.ToString()); }
public ScoreCalculator(Game game) : base(game) { }
private void Print(Game game) { Utils.ColorizeToConsole(game.ToString()); Trace.WriteLine(game.ToString()); }