Exemplo n.º 1
0
        public override Game Start(Game game)
        {
            var firstPlayerIndex = CoarseStopwatch.RandomInt32 & 1;
            var state            = new GomokuState(CharBoard.Empty(BoardSize), 0, firstPlayerIndex);
            var player           = game.Players[state.PlayerIndex];

            return(game with {
                StateJson = SerializeState(state),
                StateMessage = StandardMessages.MoveTurn(new AppUser(player.UserId)),
            });
        }
Exemplo n.º 2
0
        public StartsWith GetNextStartsWith(Random random, Maybe <Word> foundWord)
        {
            var next = _wordsByStartsWith.Keys
                       .Select(k => new
            {
                Key   = k,
                Board = CharBoard.ConstructBoard(_wordsByStartsWith[k].Select(x => new Word(x)), random),
            })
                       .Where(b => b.Board.CharCells.Count() >= 32)
                       .OrderByDescending(_ => random.Next())
                       .Select(k => k.Key)
                       .First();

            return(new StartsWith(next[0], next[1]));
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            var words = File.ReadAllLines(@".\Content\words.txt");

            _wordsByStartsWith = words
                                 .Where(w => w.Length > 2)
                                 .Select(w => new { BeginsWith = w.Substring(0, 2), Word = w.ToLower() })
                                 .GroupBy(w => w.BeginsWith)
                                 .Where(w => w.SelectMany(s => s.Word).Count() > 32)
                                 .Select(s => new { Set = s, Count = CharBoard.ConstructBoard(s.Select(r => new Word(r.Word)), null).PossibleWords.Count() })
                                 .Where(s => s.Count > 3)
                                 .Select(s => s.Set)
                                 .ToDictionary(
                k => k.Key,
                v => v.Select(r => r.Word).ToList()
                );

            Debug.WriteLine(_wordsByStartsWith.Keys.Count());
            Debug.WriteLine(_wordsByStartsWith.Values.SelectMany(v => v).Count());
        }