static public OthelloColor GetOpposite(this OthelloColor color)
 {
     if (color == OthelloColor.White)
     {
         return(OthelloColor.Black);
     }
     return(OthelloColor.White);
 }
 void AddPendingPoints(OthelloColor color, int points)
 {
     if (color == OthelloColor.White)
     {
         WhitePointsPending += points;
     }
     else
     {
         BlackPointsPending += points;
     }
 }
 void MoveDiscToCell(DiscModel disc, OthelloColor color, CellModel cell)
 {
     Debug.WriteLine($"MoveDiscToCell C={cell.Column} R={cell.Row} Disc={disc}");
     if (disc == null || cell == null)
     {
         return;
     }
     cell.Disc           = disc;
     cell.Disc.DiscColor = color;
     disc.Cell           = cell;
     _playSet.AddCell(cell);
     _playSet.AddDisc(disc);
 }
        bool IsPlayPossible(OthelloColor color)
        {
            foreach (var cell in _board.Where(c => c.Disc == null))
            {
                var acs = GetAdjacentCells(cell);

                var starts = acs.Where(c => c.Disc != null && c.Disc.DiscColor == color.GetOpposite()).ToList();

                if (!starts.Any())
                {
                    continue;
                }

                var spokes = GetSpokes(cell, starts);
                if (spokes.Any())
                {
                    return(true);
                }
            }
            return(false);
        }
        List <CellRatingModel> GetPlayableCells(OthelloColor color)
        {
            // new class e.g. CellRating?
            var cells = new List <CellRatingModel>();

            foreach (var cell in _board.Where(c => c.Disc == null))
            {
                var acs = GetAdjacentCells(cell);

                var starts = acs.Where(c => c.Disc != null && c.Disc.DiscColor == color.GetOpposite()).ToList();

                if (!starts.Any())
                {
                    continue;
                }

                var spokes = GetSpokes(cell, starts);
                if (!spokes.Any())
                {
                    continue;
                }

                // get zone
                // get points - (length of spokes * 2) + 1 ?

                var points = spokes.Sum(s => s.Count * 2) + 1;

                var cr = new CellRatingModel()
                {
                    Cell = cell, Points = points
                };

                cells.Add(cr);
            }
            return(cells);
        }
Esempio n. 6
0
 public DiscModel(OthelloColor color)
 {
     InitialColor = color;
     DiscColor    = color;
 }
 void DecrementPendingPoints(OthelloColor color)
 {
     AddPendingPoints(color, -1);
 }
 void IncrementPendingPoints(OthelloColor color)
 {
     AddPendingPoints(color, 1);
 }
        DiscModel GetNextDisc(OthelloColor color)
        {
            DiscModel disc = _discs.LastOrDefault(d => d.Cell == null && d.InitialColor == color);

            return(disc);
        }
 void MoveNextDiscToCell(OthelloColor color, CellModel cell)
 {
     MoveDiscToCell(GetNextDisc(color), color, cell);
 }