Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C# by K ( 14 years ago )
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        static Graphics gfx;
        bool dalej = true, nowa = true;
        char kolor = 'C';
        Plansza plansza;

        public class Plansza
        {
            public char[,] Pola;
            public int[,] Opcje;
            public int planszax, planszay, rozmiar, wolne_pola;
            public Plansza(int rozmiar, int x, int y)
            {
                this.rozmiar = rozmiar;
                planszax = x;
                planszay = y;
                this.Pola = new char[rozmiar,rozmiar];
                for (int i = 0; i < rozmiar; i++)
                    for (int j = 0; j < rozmiar; j++)
                        this.Pola[i,j] = 'P';
                this.wolne_pola = rozmiar * rozmiar;
            }
            public void Dodaj(int x, int y, char kolor, PaintEventArgs e)
            {
                this.Pola[x, y] = kolor;
                wolne_pola--;
                gfx = e.Graphics;
                SolidBrush farba;
                if (kolor == 'B') farba = new SolidBrush(Color.White);
                else if (kolor == 'C') farba = new SolidBrush(Color.Black);
                else farba = new SolidBrush(Color.Red);
                //farba = new SolidBrush(Color.FromArgb(10, 255, 255, 255));
                gfx.FillEllipse(farba, new Rectangle(this.planszax - 20 + x*50, this.planszay - 20 + y*50, 40, 40));
            }
            public void Dodaj(int x, int y, char kolor)
            {
                Pola[x, y] = kolor;
                wolne_pola--;
            }
            public void Rysuj(PaintEventArgs e)
            {
                gfx = e.Graphics;
                gfx.FillRectangle(new SolidBrush(Color.Gold), planszax - 50, planszay - 50, (rozmiar - 1) * 50 + 100, (rozmiar - 1) * 50 + 100);
                for (int i = planszax; i <= planszax + (rozmiar - 1)*50; i += 50)
                {
                    gfx.DrawLine(new Pen(Color.Black, 5), planszax, i, planszax + (rozmiar - 1)*50, i);
                    gfx.DrawLine(new Pen(Color.Black, 5), i, planszay, i, planszay + (rozmiar - 1)*50);
                }
            }
            public string KtoPrzegral()
            {
                
                int b = 0, c = 0;
                for (int i = 0; i < rozmiar; i++)
                {

                    for (int j = 0; j < rozmiar; j++)
                    {
                        if (Pola[i, j] == 'B')
                            b++;
                        if (Pola[i, j] == 'C')
                            c++;
                    }
                    if (b >= 3) return "Biały";
                    else if (c >= 3) return "Czarny";
                    b = 0;
                    c = 0;
                }
                for (int j = 0; j < rozmiar; j++)
                {
                    for (int i = 0; i < rozmiar; i++)
                    {
                        if (Pola[i, j] == 'B') b++;
                        if (Pola[i, j] == 'C') c++;
                    }
                    if (b >= 3) return "Biały";
                    else if (c >= 3) return "Czarny";
                    b = 0;
                    c = 0;
                }

                for (int i = 0; i <= rozmiar - 3; i++)
                {
                    for (int j = 0; j < rozmiar - i; j++)
                    {
                        if (Pola[j, j + i] == 'B') b++;
                        if (Pola[j, j + i] == 'C') c++;
                    }
                    if (b >= 3) return "Biały";
                    else if (c >= 3) return "Czarny";
                    b = 0;
                    c = 0;
                    for (int j = 0; j < rozmiar - i; j++)
                    {
                        if (Pola[j + i, j] == 'B') b++;
                        if (Pola[j + i, j] == 'C') c++;
                    }
                    if (b >= 3) return "Biały";
                    else if (c >= 3) return "Czarny";
                    b = 0;
                    c = 0;
                }
                for (int j = 0; j <= rozmiar - 3; j++)
                {
                    for (int i = 0; i < rozmiar - j; i++)
                    {
                        if (Pola[i, rozmiar - 1 - i - j] == 'B') b++;
                        if (Pola[i, rozmiar - 1 - i - j] == 'C') c++;
                    }
                    if (b >= 3) return "Biały";
                    else if (c >= 3) return "Czarny";
                    b = 0;
                    c = 0;
                    for (int i = 0; i < rozmiar - j; i++)
                    {
                        if (Pola[rozmiar - 1 - i, i + j] == 'B') b++;
                        if (Pola[rozmiar - 1 - i, i + j] == 'C') c++;
                    }
                    if (b >= 3) return "Biały";
                    else if (c >= 3) return "Czarny";
                    b = 0;
                    c = 0;
                }
                
                return "Nikt nie";
            }            
            public void IleOpcji()
            {
                int b = 0, c = 0, bi = 0, ci = 0;
                Opcje = new int[2, rozmiar * 5];
                for (int i = 0; i < rozmiar; i++)
                {

                    for (int j = 0; j < rozmiar; j++)
                    {
                        if (Pola[i, j] == 'B')
                            b++;
                        if (Pola[i, j] == 'C')
                            c++;
                    }
                    Opcje[0, bi++] = b;
                    Opcje[1, ci++] = c;
                    b = 0;
                    c = 0;
                }
                for (int j = 0; j < rozmiar; j++)
                {
                    for (int i = 0; i < rozmiar; i++)
                    {
                        if (Pola[i, j] == 'B') b++;
                        if (Pola[i, j] == 'C') c++;
                    }
                    Opcje[0, bi++] = b;
                    Opcje[1, ci++] = c;
                    b = 0;
                    c = 0;
                }

                for (int i = 0; i <= rozmiar - 3; i++)
                {
                    for (int j = 0; j < rozmiar - i; j++)
                    {
                        if (Pola[j, j + i] == 'B') b++;
                        if (Pola[j, j + i] == 'C') c++;
                    }
                    Opcje[0, bi++] = b;
                    Opcje[1, ci++] = c;
                    b = 0;
                    c = 0;
                    for (int j = 0; j < rozmiar - i; j++)
                    {
                        if (Pola[j + i, j] == 'B') b++;
                        if (Pola[j + i, j] == 'C') c++;
                    }
                    Opcje[0, bi++] = b;
                    Opcje[1, ci++] = c;
                    b = 0;
                    c = 0;
                }
                for (int j = 0; j <= rozmiar - 3; j++)
                {
                    for (int i = 0; i < rozmiar - j; i++)
                    {
                        if (Pola[i, rozmiar - 1 - i - j] == 'B') b++;
                        if (Pola[i, rozmiar - 1 - i - j] == 'C') c++;
                    }
                    Opcje[0, bi++] = b;
                    Opcje[1, ci++] = c;
                    b = 0;
                    c = 0;
                    for (int i = 0; i < rozmiar - j; i++)
                    {
                        if (Pola[rozmiar - 1 - i, i + j] == 'B') b++;
                        if (Pola[rozmiar - 1 - i, i + j] == 'C') c++;
                    }
                    Opcje[0, bi++] = b;
                    Opcje[1, ci++] = c;
                    b = 0;
                    c = 0;
                }
            }             
        }

        public class Ruch
        {
            public int[] wartosc;
            public int x;
            public int y;
            public char kolor;
            public char test;
            public Ruch(Plansza plansza)
            {
                wartosc = new int[3];
                wartosc[0] = 0;
                wartosc[1] = 0;
                wartosc[2] = plansza.rozmiar * 4; 
            }
            public Ruch(int x, int y, char kolor, Plansza plansza)
            {
                this.x = x;
                this.y = y;
                this.kolor = kolor;
                wartosc = new int[3];
                Plansza po_ruchu = plansza;                
                po_ruchu.Dodaj(x, y, kolor);

                if (po_ruchu.KtoPrzegral() != "Nikt nie")
                {
                    wartosc[0] = 0;
                    wartosc[1] = 0;
                    wartosc[2] = plansza.rozmiar * 4;
                    return;
                }
                po_ruchu.IleOpcji();
                int i;
                if (kolor == 'B') i = 0;
                else i = 1;
                int ilosc0 = 0, ilosc1 = 0, ilosc2 = 0;
                for (int j = 0; j < po_ruchu.rozmiar * 5; j++)
                {
                    if (po_ruchu.Opcje[i, j] == 2) ilosc2++;
                    else if (po_ruchu.Opcje[i, j] == 1) ilosc1++;
                    else ilosc0++;
                }
                wartosc[0] = ilosc0;
                wartosc[1] = ilosc1;
                wartosc[2] = ilosc2;
            }
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (nowa)
            {
                plansza = new Plansza(5, 70, 70);
                label3.Text = "Ruch Czarnego";
            }
            nowa = false;
            plansza.Rysuj(e);
            /*
            if (rysowanie)
            {
                Random random = new Random();
                for (int i = 0; i <= 200; i++)
                {
                    int x = random.Next(plansza.rozmiar), y = random.Next(plansza.rozmiar), z = random.Next(2);
                    char kol;
                    if (z) kol = 'B';
                    else kol = 'C';
                    
                    plansza.Dodaj(x, y, kol, e);                  
                    
                }
                z = !z;
            }
            mozna_polprzezroczyste = true;
            */
        }

        private void button1_Click(object sender, EventArgs e)
        {
            plansza = new Plansza(5, 70, 70);
            plansza.Rysuj(new PaintEventArgs(this.CreateGraphics(), new Rectangle()));
            dalej = true;
            label1.Text = "";
            label3.Text = "Ruch Czarnego";
            kolor = 'C';
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            /*label2.Text = (Form1.MousePosition.X - this.Location.X)  + ", " + (Form1.MousePosition.Y - this.Location.Y);
            /*
            PaintEventArgs p = new PaintEventArgs(this.CreateGraphics(), new Rectangle());
            gfx = p.Graphics;

            
             /*
            {
                x = Form1.MousePosition.X; 
                y = Form1.MousePosition.Y;
                SolidBrush farba;
                if (kolor == 'B') farba = new SolidBrush(Color.FromArgb(150, 255, 255, 255));
                else if (kolor == 'C') farba = new SolidBrush(Color.FromArgb(150, 0, 0, 0));
                else farba = new SolidBrush(Color.Red);
                gfx.FillEllipse(farba, new Rectangle(Form1.MousePosition.X - Form1.MousePosition.X / 50, Form1.MousePosition.Y - Form1.MousePosition.Y / 50, 40, 40));
            }
            else plansza.Rysuj(p);
             */
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            int x = Form1.MousePosition.X - this.Location.X, y = Form1.MousePosition.Y - this.Location.X;
            if (dalej &&
                x >= plansza.planszax - 25 && x <= plansza.planszax + (plansza.rozmiar - 1) * 50 + 25 &&
                y >= plansza.planszay - 25 && y <= plansza.planszay + (plansza.rozmiar - 1) * 50 + 25)
            {
                if (plansza.Pola[(x - plansza.planszax + 25) / 50, (y - plansza.planszay) / 50] == 'P')
                {
                    plansza.Dodaj((x - plansza.planszax + 25) / 50, (y - plansza.planszay) / 50, kolor, new PaintEventArgs(this.CreateGraphics(), new Rectangle()));
                    if (kolor == 'C')
                    {
                        kolor = 'B';
                        label3.Text = "Ruch Białego";
                    }
                    else if (kolor == 'B')
                    {
                        kolor = 'C';
                        label3.Text = "Ruch Czarnego";
                    }
                }
                if (plansza.KtoPrzegral() != "Nikt nie")
                {
                    dalej = false;
                    label3.Text = "";
                }
                label1.Text = plansza.KtoPrzegral() + " zasysa";
            }
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {            
            Ruch[] ruchy = new Ruch[plansza.wolne_pola];

            int n = 0;
            for (int i = 0; i < plansza.rozmiar; i++)
            {
                for (int j = 0; j < plansza.rozmiar; j++)
                {
                    if (plansza.Pola[i, j] == 'P')
                    {
                        ruchy[n++] = new Ruch(i, j, kolor, plansza);
                        if (i == 0 && j == 0 && ruchy[n - 1].test == 'T') label2.Text += "BLE";
                        else if (i == 0 && j == 0) label2.Text += "GIT";
                    }
                }
            }
            if (plansza.Pola[0, 3] == 'C') label2.Text += 'T';
            else label2.Text += 'N';



            /*
            int[] wartosci_ruchow = new int[ruchy.Length];
            int max = 0, ktory = -1;
            for (int i = 0; i < wartosci_ruchow.Length; i++)
            {
                wartosci_ruchow[i] = ruchy[i].wartosc[0] * 100 + ruchy[i].wartosc[1] * 10 + ruchy[i].wartosc[2];
                if (wartosci_ruchow[i] > max) ktory = i;
                max = Math.Max(max, wartosci_ruchow[i]);
               
            }
             * */
            Ruch[] najlepsze = new Ruch[1];
            najlepsze[0] = new Ruch(plansza);

            for (int i = 0; i < 5; i++)
            {
                label2.Text += plansza.Pola[i, 0];
            }

            for (int i = 0; i < ruchy.Length; i++)
            {
                if (ruchy[i].wartosc[0] > najlepsze[0].wartosc[0])
                {
                    najlepsze = new Ruch[1];
                    najlepsze[0] = ruchy[i];
                }
                else if (ruchy[i].wartosc[0] < najlepsze[0].wartosc[0])
                { }
                else
                {
                    if (ruchy[i].wartosc[1] > najlepsze[0].wartosc[1])
                    {
                        najlepsze = new Ruch[1];
                        najlepsze[0] = ruchy[i];
                    }
                    else if (ruchy[i].wartosc[1] < najlepsze[0].wartosc[1])
                    { }
                    else
                    {
                        if (ruchy[i].wartosc[2] > najlepsze[0].wartosc[2])
                        {
                            najlepsze = new Ruch[1];
                            najlepsze[0] = ruchy[i];
                        }
                        else if (ruchy[i].wartosc[2] < najlepsze[0].wartosc[2])
                        { }
                        else
                        {
                            Array.Resize<Ruch>(ref najlepsze, najlepsze.Length + 1);
                            najlepsze[najlepsze.Length - 1] = ruchy[i];
                        }
                    }
                }
            }
             
            Random los = new Random();
            int indeks = los.Next(0, najlepsze.Length);
            int x = najlepsze[indeks].x, y = najlepsze[indeks].y;
            
            plansza.Dodaj(x, y, kolor, new PaintEventArgs(this.CreateGraphics(), new Rectangle()));
            if (kolor == 'C')
            {
                kolor = 'B';
                label3.Text = "Ruch Białego";
            }
            else if (kolor == 'B')
            {
                kolor = 'C';
                label3.Text = "Ruch Czarnego";
            }
            if (plansza.KtoPrzegral() != "Nikt nie")
            {
                dalej = false;
                label3.Text = "";
            }
            label1.Text = plansza.KtoPrzegral() + " zasysa";
        }
    }
}DMXP7

 

Revise this Paste

Your Name: Code Language: