Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading.Tasks;
- namespace Bingo
- {
- public static class global
- {
- public static string Mode;
- public static int i, j;
- public static int[,] COM_Board= new int [6,6];
- public static int[,] Human_Board = new int[6,6];
- }
- class Program
- {
- public static void PrintHumanBoard()
- {
- for (int i=1;i<=5;i++)
- {
- for (int j = 1; j <= 5; j++)
- if (global.Human_Board[i, j] == 0)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- if (global.Human_Board[i, j] < 10)
- Console.Write("{0} ", global.Human_Board[i, j]);
- else Console.Write("{0} ", global.Human_Board[i, j]);
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- {
- if (global.Human_Board[i, j] < 10)
- Console.Write("{0} ", global.Human_Board[i, j]);
- else Console.Write("{0} ", global.Human_Board[i, j]);
- }
- Console.WriteLine();
- }
- }
- public static void PrintCOMBoard()
- {
- for (int i = 1; i <= 5; i++)
- {
- for (int j = 1; j <= 5; j++)
- if (global.COM_Board[i, j] == 0)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- if (global.COM_Board[i, j] < 10)
- Console.Write("{0} ", global.COM_Board[i, j]);
- else Console.Write("{0} ", global.COM_Board[i, j]);
- Console.ForegroundColor = ConsoleColor.White;
- }
- else
- {
- if (global.COM_Board[i, j] < 10)
- Console.Write("{0} ", global.COM_Board[i, j]);
- else Console.Write("{0} ", global.COM_Board[i, j]);
- }
- Console.WriteLine();
- }
- }
- public static void Sout(string S)
- {
- Console.WriteLine(S);
- Task.Delay(1000);
- }
- public static void Info()
- {
- Sout("Made by Tran Viet Anh");
- Sout("Do not copy");
- }
- public static void Init_Board()
- {
- Console.Write("Choose mode: ");
- global.Mode = Console.ReadLine();
- global.Mode = global.Mode.ToUpper();
- while ((global.Mode!="EASY") && (global.Mode!="NORMAL"))
- {
- Console.Write("Mode inputed is invalid, please input again: ");
- global.Mode = Console.ReadLine();
- global.Mode = global.Mode.ToUpper();
- }
- Console.Write("Make board by manual or auto? ");
- string Choice = Console.ReadLine();
- Choice = Choice.ToUpper();
- while (Choice=="INFO")
- {
- Info();
- Console.Write("Input command again: ");
- Choice = Console.ReadLine();
- Choice = Choice.ToUpper();
- }
- while ((Choice!="AUTO") && (Choice!="MANUAL"))
- {
- Console.Write("Command inputed is invalid, please input again: ");
- Choice = Console.ReadLine();
- Choice = Choice.ToUpper();
- }
- if (Choice=="AUTO")
- {
- int value = 0;
- for (int i=1;i<=5;i++)
- for (int j=1;j<=5;j++)
- {
- value++;
- global.Human_Board[i, j] = value;
- }
- Random Rnd = new Random();
- for (int i=1;i<=5;i++)
- for (int j=1;j<=5;j++)
- {
- int x = Rnd.Next(5) + 1;
- int y = Rnd.Next(5) + 1;
- //Swap
- int Mid = global.Human_Board[i, j];
- global.Human_Board[i, j] = global.Human_Board[x, y];
- global.Human_Board[x, y] = Mid;
- }
- value = 0;
- for (int i = 1; i <= 5; i++)
- for (int j = 1; j <= 5; j++)
- {
- value++;
- global.COM_Board[i, j] = value;
- }
- for (int i = 1; i <= 5; i++)
- for (int j = 1; j <= 5; j++)
- {
- int x = Rnd.Next(5) + 1;
- int y = Rnd.Next(5) + 1;
- //Swap
- int Mid = global.COM_Board[i, j];
- global.COM_Board[i, j] = global.COM_Board[x, y];
- global.COM_Board[x, y] = Mid;
- }
- PrintHumanBoard();
- PrintCOMBoard();
- }
- }
- public static void Tie()
- {
- Console.Clear();
- PrintHumanBoard();
- Console.WriteLine();
- PrintCOMBoard();
- Console.Write("TIE");
- Console.ReadLine();
- }
- public static void ComputerWon()
- {
- Console.Clear();
- PrintHumanBoard();
- Console.WriteLine();
- PrintCOMBoard();
- Console.WriteLine("COM WON!");
- Console.ReadLine();
- }
- public static void HumanWon()
- {
- Console.Clear();
- PrintHumanBoard();
- Console.WriteLine();
- PrintCOMBoard();
- Console.WriteLine("HUMAN WON!");
- Console.ReadLine();
- }
- public static int HumanDiagonalScore()
- {
- int count = 0, c = 0;
- for (int i = 1; i <= 5; i++)
- if (global.COM_Board[i, i] == 0) c++;
- if (c == 5) count++;
- for (int i = 1; i <= 5; i++)
- if (global.COM_Board[i, 5 - i + 1] == 0) c++;
- if (c == 5) count++;
- return count;
- }
- public static int HumanLineScore()
- {
- int Score=0;
- for (int i=1;i<=5;i++)
- {
- int LineScore = 0;
- for (int j = 1; j <= 5; j++)
- if (global.Human_Board[i, j] == 0) LineScore++;
- if (LineScore == 5) Score++;
- }
- return Score;
- }
- public static int HumanColumnScore()
- {
- int Score = 0;
- for (int i = 1; i <= 5; i++)
- {
- int LineScore = 0;
- for (int j = 1; j <= 5; j++)
- if (global.Human_Board[i, j] == 0) LineScore++;
- if (LineScore == 5) Score++;
- }
- return Score;
- }
- public static int COMDiagonalScore()
- {
- int count = 0, c = 0;
- for (int i = 1; i <= 5; i++)
- if (global.COM_Board[i, i] == 0) c++;
- if (c == 5) count++;
- for (int i = 1; i <= 5; i++)
- if (global.COM_Board[i, 5-i+1] == 0) c++;
- if (c == 5) count++;
- return count;
- }
- public static int COMColumnScore()
- {
- int Count = 0;
- for (int j = 1; j <= 5; j++)
- {
- int c = 0;
- for (int i = 1; i <= 5; i++)
- if (global.COM_Board[i, j] == 0) c++;
- if (c == 5) Count++;
- }
- return Count;
- }
- public static int COMLineScore()
- {
- int Count = 0;
- for (int i = 1; i <= 5; i++)
- {
- int c = 0;
- for (int j = 1; j <= 5; j++)
- if (global.COM_Board[i, j] == 0) c++;
- if (c == 5) Count++;
- }
- return Count;
- }
- public static bool COMVictoryCondition()
- {
- int Score = 0;
- Score = Score + COMLineScore();
- Score = Score + COMColumnScore();
- Score = Score + COMDiagonalScore();
- if (Score >= 5) return true;
- else return false;
- }
- public static bool HumanVictoryCondition()
- {
- int Score = 0;
- Score = Score + HumanLineScore();
- Score = Score + HumanColumnScore();
- Score = Score + HumanDiagonalScore();
- if (Score >= 5) return true;
- else return false;
- }
- public static bool ValidChoice(int Choice)
- {
- if ((Choice < 1) || (Choice > 25)) return false;
- else
- {
- bool B = false;
- for (int i=1;i<=5;i++)
- for (int j=1;j<=5;j++)
- if (global.Human_Board[i,j]==Choice)
- {
- B = true;
- break;
- }
- return B;
- }
- }
- public static bool ValidCOMChoice(int Value)
- {
- bool B = false;
- for (int i=1;i<=5;i++)
- for (int j=1;j<=5;j++)
- if (global.COM_Board[i,j]==Value)
- {
- B = true;
- break;
- }
- return B;
- }
- public static int EasyBot()
- {
- int COMChoice;
- Random Rnd = new Random();
- COMChoice = Rnd.Next(25) + 1;
- while (!ValidCOMChoice(COMChoice))
- COMChoice = Rnd.Next(25) + 1;
- return COMChoice;
- }
- public static void Play()
- {
- int Choice = 0;
- while (!(HumanVictoryCondition()) && !(COMVictoryCondition()))
- {
- Console.Clear();
- PrintHumanBoard();
- Console.WriteLine();
- Console.Write("Input Choice: ");
- Choice = int.Parse(Console.ReadLine());
- while (!(ValidChoice(Choice)))
- {
- Console.WriteLine("Invalid value, input again: ");
- Choice = int.Parse(Console.ReadLine());
- }
- for (int i = 1; i <= 5; i++)
- for (int j = 1; j <= 5; j++)
- if (global.Human_Board[i, j] == Choice) global.Human_Board[i, j] = 0;
- for (int i = 1; i <= 5; i++)
- for (int j = 1; j <= 5; j++)
- if (global.COM_Board[i, j] == Choice) global.COM_Board[i, j] = 0;
- if ((HumanVictoryCondition()) == (COMVictoryCondition()))
- {
- if (HumanVictoryCondition() == true)
- Tie();
- }
- else
- if (HumanVictoryCondition() == true)
- HumanWon();
- else ComputerWon();
- if (global.Mode == "EASY") Choice = EasyBot();
- Console.Write("COM Choice: ");
- System.Threading.Thread.Sleep(1000);
- Console.WriteLine(Choice);
- System.Threading.Thread.Sleep(1000);
- for (int i = 1; i <= 5; i++)
- for (int j = 1; j <= 5; j++)
- if (global.Human_Board[i, j] == Choice) global.Human_Board[i, j] = 0;
- for (int i = 1; i <= 5; i++)
- for (int j = 1; j <= 5; j++)
- if (global.COM_Board[i, j] == Choice) global.COM_Board[i, j] = 0;
- if ((HumanVictoryCondition()) == (COMVictoryCondition()))
- {
- if (HumanVictoryCondition() == true)
- Tie();
- }
- else
- if (HumanVictoryCondition() == true)
- HumanWon();
- else ComputerWon();
- }
- }
- static void Main(string[] args)
- {
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.White;
- Init_Board();
- Play();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement