private void KonwertujKolor(TypObiektu typ, out Checkers.Logic.Color kolor, out Checkers.Logic.Type kolor2) { kolor = Checkers.Logic.Color.White; kolor2 = Checkers.Logic.Type.Man; switch (typ) { case RozpoznawaniePlanszy.TypObiektu.Pionki: kolor = Checkers.Logic.Color.Black; kolor2 = Checkers.Logic.Type.Man; break; case RozpoznawaniePlanszy.TypObiektu.Damki: kolor = Checkers.Logic.Color.Black; kolor2 = Checkers.Logic.Type.King; break; case RozpoznawaniePlanszy.TypObiektu.PionkiWrog: kolor = Checkers.Logic.Color.White; kolor2 = Checkers.Logic.Type.Man; break; case RozpoznawaniePlanszy.TypObiektu.DamkiWrog: kolor = Checkers.Logic.Color.White; kolor2 = Checkers.Logic.Type.King; break; } }
private void btnStart_Click(object sender, EventArgs e) { //Początek int ile = plansza.RozpoznajPola(); if (ile != 32) { return; } RozpoznawaniePlanszy.Pionek[] p = plansza.RozpoznajPionki(); Client = CreateProcess("Test_Client.py"); Server = CreateProcess("Test_Server.py"); Checkers.Logic.Color kolor; Checkers.Logic.Type typ; Checkers_piece[,] pl = new Checkers_piece[8, 8]; for (int i = 0; i < p.Length; i++) { KonwertujKolor(p[i].typ, out kolor, out typ); pl[p[i].y, p[i].x] = new Checkers_piece(kolor, typ); } Checkers.Logic.Draughts_checkers dc = new Draughts_checkers(8, 12); int bialy = dc.Generate_player_key(Checkers.Logic.Color.White); int czarny = dc.Generate_player_key(Checkers.Logic.Color.Black); //dc.Set_board(Checkers.Logic.Color.Black, pl); dc.Set_active_player(Checkers.Logic.Color.White); wnd.Show(); while (true) { Thread.Sleep(300); Application.DoEvents(); //Petla ile = plansza.RozpoznajPola(); if (ile != 32) { continue; } p = plansza.RozpoznajPionki(); Checkers.Logic.Color k = Checkers.Logic.Color.Black; Coordinates[] move = null; PokazPlansze(p); try { pl = new Checkers_piece[8, 8]; for (int i = 0; i < p.Length; i++) { KonwertujKolor(p[i].typ, out kolor, out typ); pl[p[i].y, p[i].x] = new Checkers_piece(kolor, typ); } move = Move_Detector.DetectMove(dc.Check_active_player(), dc, pl); k = dc.Check_active_player(); Make_move_and_display_boards(ref dc, (k == Checkers.Logic.Color.Black ? czarny : bialy), new Coordinates(move[0].X, move[0].Y), new Coordinates(move[1].X, move[1].Y)); } catch (Exception ex) { //MessageBox.Show(ex.Message); lblBlad.Text = ex.Message; continue; } if (k == Checkers.Logic.Color.Black) { Client.StandardInput.WriteLine(move[0].X); Client.StandardInput.WriteLine(move[0].Y); Client.StandardInput.WriteLine(move[1].X); Client.StandardInput.WriteLine(move[1].Y); } else { Server.StandardInput.WriteLine(move[0].X); Server.StandardInput.WriteLine(move[0].Y); Server.StandardInput.WriteLine(move[1].X); Server.StandardInput.WriteLine(move[1].Y); } } }