Beispiel #1
0
        static bool IsWinner(cell a, cell b, cell c)
        {
            char[,] p = playfield;

            char first  = p[a.x, a.y];
            char second = p[b.x, b.y];
            char third  = p[c.x, c.y];

            return(first == second && second == third);
        }
Beispiel #2
0
        static bool WinnerWinnerChickenDinner(int player)
        {
            List <List <int[, ]> > posibilities = new List <List <int[, ]> > {
                new List <int[, ]> {
                    new int[, ] {
                        { 0 }, { 0 }
                    },
                    new int[, ] {
                        { 0 }, { 1 }
                    },
                    new int[, ] {
                        { 0 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 1 }, { 0 }
                    },
                    new int[, ] {
                        { 1 }, { 1 }
                    },
                    new int[, ] {
                        { 1 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 2 }, { 0 }
                    },
                    new int[, ] {
                        { 2 }, { 1 }
                    },
                    new int[, ] {
                        { 2 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 0 }, { 0 }
                    },
                    new int[, ] {
                        { 1 }, { 0 }
                    },
                    new int[, ] {
                        { 2 }, { 0 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 0 }, { 1 }
                    },
                    new int[, ] {
                        { 1 }, { 1 }
                    },
                    new int[, ] {
                        { 2 }, { 1 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 0 }, { 2 }
                    },
                    new int[, ] {
                        { 1 }, { 2 }
                    },
                    new int[, ] {
                        { 2 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 1 }, { 0 }
                    },
                    new int[, ] {
                        { 1 }, { 1 }
                    },
                    new int[, ] {
                        { 1 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 2 }, { 0 }
                    },
                    new int[, ] {
                        { 2 }, { 1 }
                    },
                    new int[, ] {
                        { 2 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 0 }, { 0 }
                    },
                    new int[, ] {
                        { 1 }, { 1 }
                    },
                    new int[, ] {
                        { 2 }, { 2 }
                    }
                },
                new List <int[, ]> {
                    new int[, ] {
                        { 2 }, { 0 }
                    },
                    new int[, ] {
                        { 1 }, { 1 }
                    },
                    new int[, ] {
                        { 0 }, { 2 }
                    }
                },
            };

            foreach (var list in posibilities)
            {
                cell a = new cell
                {
                    x = list[0][0, 0],
                    y = list[0][1, 0]
                };
                cell b = new cell
                {
                    x = list[1][0, 0],
                    y = list[1][1, 0]
                };
                cell c = new cell
                {
                    x = list[2][0, 0],
                    y = list[2][1, 0]
                };
                if (IsWinner(a, b, c))
                {
                    Console.WriteLine("Player {0} has won.", player);
                    return(true);
                }
            }
            return(false);
        }