Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp11
- {
- class Node
- {
- public char[][] polegry;
- public List<Node> children;
- public Node(char[][] value)
- {
- polegry = value;
- children = null;
- }
- public bool isLeaf(ref Node node)
- {
- return(children == null);
- }
- public void insertData(ref Node node, char[][] data)
- {
- if (node == null)
- {
- node = new Node(data);
- }
- else children.Add(new Node(data));
- }
- public bool search(Node node, char[][] s)
- {
- if (node == null) return false;
- if (node.polegry == s)
- {
- return true;
- }
- else
- {
- foreach (Node element in children)
- {
- if (node.search(element, s)) return true;
- }
- return false;
- }
- }
- public void display(Node n)
- {
- if (n == null) return;
- foreach (Node element in children)
- {
- for (int i = 0; i < 10; i++)
- {
- for (int k = 0; k < 10; k++)
- {
- Console.Write(polegry[i][k]);
- }
- Console.Write("\n");
- }
- }
- }
- }
- class BinaryTree
- {
- private Node root;
- private int count;
- public BinaryTree()
- {
- root = null;
- count = 0;
- }
- public bool isEmpty()
- {
- return root == null;
- }
- public void insert(char[][] d)
- {
- if (isEmpty())
- {
- root = new Node(d);
- }
- else
- {
- root.insertData(ref root, d);
- }
- count++;
- }
- public bool search(char[][] s)
- {
- return root.search(root, s);
- }
- public bool isLeaf()
- {
- if (!isEmpty())
- return root.isLeaf(ref root);
- return true;
- }
- public void display()
- {
- if (!isEmpty())root.display(root);
- }
- public int Count()
- {
- return count;
- }
- }
- class Program
- {
- static char[][] polegry;
- static int ROW = 10;
- static int COL = 10;
- static int min(int a, int b)
- {
- if (a < b) return a;
- else return b;
- }
- static int max(int a, int b)
- {
- if (a > b) return a;
- else return b;
- }
- static bool isGameOver(char[][] polegry)
- {
- for (int i = 0; i < 10; i++)
- {
- for (int k = 0; k < 10; k++)
- {
- if (polegry[i][k] == 0) return false;
- }
- }
- return true;
- }
- static int[] evaluateBoard(char[][] polegry)
- {
- int[] tab = new int[2];
- tab[0] = policzbiale(polegry);
- tab[1] = policzczarne(polegry);
- return tab;
- }
- static int minimax(Node node, int depth, bool maximizingPlayer)
- {
- if (depth == 0 || isGameOver(node.polegry))
- {
- int[] tab = new int[2];
- tab = evaluateBoard(node.polegry);
- return tab[0]+ (-1)*tab[1];
- }
- if (maximizingPlayer)
- {
- int value = -9999;
- foreach (Node element in node.children)
- {
- value = max(value, minimax(element, depth - 1, false));
- }
- return value;
- }
- else
- {
- int value = 9999;
- foreach (Node element in node.children)
- {
- value = min(value, minimax(element, depth - 1, true));
- }
- return value;
- }
- }
- static void wypisz(char[][] polegry)
- {
- for (int i = 0; i < ROW; i++)
- {
- Console.WriteLine(polegry[i]);
- }
- }
- static int policzbiale(char[][] polegry)
- {
- int wynik = 0;
- for (int i = 0; i < 10; i++)
- {
- String napis = String.Empty;
- for (int k = 0; k < 10; k++) napis += polegry[i][k];
- while (napis.Contains("1111"))
- {
- napis = napis.Remove(napis.IndexOf("1111"),4);
- wynik++;
- }
- }
- for (int i = 0; i < 10; i++)
- {
- String napis2 = String.Empty;
- for (int k = 0; k < 10; k++) napis2 += polegry[k][i];
- while (napis2.Contains("1111"))
- {
- napis2 = napis2.Remove(napis2.IndexOf("1111"), 4);
- wynik++;
- }
- }
- for (int line = 1; line <= (ROW + COL - 1); line++)
- {
- String napis5 = String.Empty;
- int start_col = Math.Max(0, line - ROW);
- int count = Math.Min(line, Math.Min((COL - start_col), ROW));
- for (int j = 0; j < count; j++) napis5 += polegry[Math.Min(ROW, line) - j - 1][start_col + j];
- while (napis5.Contains("1111"))
- {
- napis5 = napis5.Remove(napis5.IndexOf("1111"), 4);
- wynik++;
- }
- }
- char[][] invpolegry = new char[10][];
- for (int i = 0; i < 10; i++)
- {
- invpolegry[i] = new char[10];
- }
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- invpolegry[i][j] = polegry[i][9 - j];
- }
- }
- for (int line = 1; line <= (ROW + COL - 1); line++)
- {
- String napis6 = String.Empty;
- int start_col = Math.Max(0, line - ROW);
- int count = Math.Min(line, Math.Min((COL - start_col), ROW));
- for (int j = 0; j < count; j++) napis6 += invpolegry[Math.Min(ROW, line) - j - 1][start_col + j];
- while (napis6.Contains("1111"))
- {
- napis6 = napis6.Remove(napis6.IndexOf("1111"), 4);
- wynik++;
- }
- }
- return wynik;
- }
- static int policzczarne(char[][] polegry)
- {
- int wynik = 0;
- for (int i = 0; i < 10; i++)
- {
- String napis = String.Empty;
- for (int k = 0; k < 10; k++) napis += polegry[i][k];
- while (napis.Contains("2222"))
- {
- napis = napis.Remove(napis.IndexOf("2222"), 4);
- wynik++;
- }
- }
- for (int i = 0; i < 10; i++)
- {
- String napis2 = String.Empty;
- for (int k = 0; k < 10; k++) napis2 += polegry[k][i];
- while (napis2.Contains("2222"))
- {
- napis2 = napis2.Remove(napis2.IndexOf("2222"), 4);
- wynik++;
- }
- }
- for (int line = 1; line <= (ROW + COL - 1); line++)
- {
- String napis5 = String.Empty;
- int start_col = Math.Max(0, line - ROW);
- int count = Math.Min(line, Math.Min((COL - start_col), ROW));
- for (int j = 0; j < count; j++) napis5 += polegry[Math.Min(ROW, line) - j - 1][start_col + j];
- while (napis5.Contains("2222"))
- {
- napis5 = napis5.Remove(napis5.IndexOf("2222"), 4);
- wynik++;
- }
- }
- char[][] invpolegry = new char[10][];
- for (int i = 0; i < 10; i++)
- {
- invpolegry[i] = new char[10];
- }
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- invpolegry[i][j] = polegry[i][9 - j];
- }
- }
- for (int line = 1; line <= (ROW + COL - 1); line++)
- {
- String napis6 = String.Empty;
- int start_col = Math.Max(0, line - ROW);
- int count = Math.Min(line, Math.Min((COL - start_col), ROW));
- for (int j = 0; j < count; j++) napis6 += invpolegry[Math.Min(ROW, line) - j - 1][start_col + j];
- while (napis6.Contains("2222"))
- {
- napis6 = napis6.Remove(napis6.IndexOf("2222"), 4);
- wynik++;
- }
- }
- return wynik;
- }
- static void Main(string[] args)
- {
- polegry = new char[10][];
- for (int i = 0; i < 10; i++)
- {
- polegry[i] = new char[10];
- }
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- polegry[i][j] = '0';
- }
- }
- polegry[0] = "0000000000".ToCharArray();
- polegry[1] = "2222122220".ToCharArray();
- polegry[2] = "1111011110".ToCharArray();
- polegry[3] = "0002000000".ToCharArray();
- polegry[4] = "0000000000".ToCharArray();
- polegry[5] = "0000000000".ToCharArray();
- polegry[6] = "0000000000".ToCharArray();
- polegry[7] = "0000000000".ToCharArray();
- polegry[8] = "0000000000".ToCharArray();
- polegry[9] = "0000000000".ToCharArray();
- wypisz(polegry);
- int[] tab = new int[2];
- tab = evaluateBoard(polegry);
- Console.WriteLine("Punkty bialych:" + tab[0]);
- Console.WriteLine("Punkty czarnych:" + tab[1]);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement