protected virtual void UradiPotez(Potez p) { string info; if (context.TrenutnoStanje.Potez(context.NaPotezu, p.x, p.y, out info)) { OsveziPrikaz(); int igrac; if (context.TrenutnoStanje.DaLiJeKraj(out igrac)) { if (igrac == 1) { MessageBox.Show("Pobedio X"); } else { MessageBox.Show("Pobedio O"); } return; } context.Sledeci(); if (context.NaPotezu == 1) { lblIgrac.Text = btnX.Text; } else { lblIgrac.Text = btnO.Text; } } else { MessageBox.Show(info); } }
public PotezView(Potez o) { this.RedniBr = o.RedniBr; this.PocetnoPolje = o.PocetnoPolje; this.KrajnjePolje = o.KrajnjePolje; this.Vreme = o.Vreme; }
public async Task <IActionResult> PauzirajIgru() { string igraId = User.FindFirstValue("sub"); string email = User.FindFirstValue("email"); Boja bojaIgraca = Enum.Parse <Boja>(User.FindFirstValue("Boja")); Korisnik korisnik = await KorisnikProvider.GetKorisnik(db, email); Igra game = await GameProvider.NadjiIgruId(db, igraId); if (game.kreatorIgre.ID != korisnik.ID) { return(BadRequest()); } Potez poslednji = await GameProvider.getPoslednjiPotezIgre(db, game); if (game.status != statusIgre.uToku || !game.privateGame || (game.status == statusIgre.uToku && game.naPotezu == poslednji.potezOdigrao)) { return(Forbid()); } game.status = statusIgre.pauzirana; await GameProvider.AzurirajIgru(db, game); await GameHubHelper.pauzirajIgruNotifyAsync(_gameHub, game.groupNameGUID); return(Ok()); }
public void OdigrajPotez(Point loc) { _model.ZauzmiPolje(loc.X, loc.Y); Potez p = new Potez() { PostavljenaFigura = _model.DajSelektovanu(), Pozicija = loc }; _view.PrikaziPotez(p); //for(int i=0;i<16;i++) //MessageBox.Show(_model.DajFiguruZaIzbor(i).Ime + "\n" + _model.DajFiguruZaIzbor(i).ReprezentacijaBrojem()); if (KrajIgre()) { _view.Nereseno(); return; } if (DaLijeNekoPobedio()) { _view.Pobeda(); return; } _view.AzurirajPoruku(_model.TrenutniIgrac()); _model.SledeciIgrac(); PotezAi(); }
public async Task <IActionResult> OdigrajPotez(int figuraIndex) { string igraId = User.FindFirstValue("sub"); Boja bojaIgraca = Enum.Parse <Boja>(User.FindFirstValue("Boja")); Igra game = await GameProvider.NadjiIgruFigure(db, igraId); if (game == null) { return(NotFound()); } if (game.status != statusIgre.uToku || game.naPotezu != bojaIgraca || !game.aleaIactaEst) { return(Forbid()); } Potez poslednjiPotez = await GameProvider.getPoslednjiPotezIgre(db, game); if (poslednjiPotez.potezOdigrao != bojaIgraca) { return(NotFound()); } Figura izabranaFigura = game.figure.Where(Figura => Figura.index == figuraIndex && Figura.boja == bojaIgraca).FirstOrDefault(); poslednjiPotez.izabranaFigura = izabranaFigura; if (izabranaFigura == null) { return(NotFound()); } List <Tuple <int, int> > potezi = game.odigrajPotez(izabranaFigura, poslednjiPotez.vrKocke, bojaIgraca); if (potezi == null) { return(NotFound()); } game.aleaIactaEst = !game.aleaIactaEst; if (poslednjiPotez.vrKocke != 6) { game.naPotezu = (Igra.redosledPoteza.Find(bojaIgraca).Next ?? Igra.redosledPoteza.First).Value; } await GameProvider.AzurirajIgru(db, game); await GameProvider.AzurirajPotez(db, poslednjiPotez); await GameHubHelper.figuraPomerenaNotifyAsync(_gameHub, game.groupNameGUID, potezi, poslednjiPotez.vrKocke != 6); if (game.kraj() != null) { await GameHubHelper.krajIgreNotifyAsync(_gameHub, game.groupNameGUID, game.kraj()); } return(Ok()); }
public int AddPotez(Potez value) { ISession s = DataLayer.GetSession(); s.Save(value); s.Flush(); s.Close(); return(1); }
private void btnIzmeniPotez_Click(object sender, EventArgs e) { if (lstPotez.SelectedItems.Count == 0) { return; } Potez p = (Potez)lstPotez.SelectedItems[0]; p.PocetnoPolje = txtPoc.Text; p.KrajnjePolje = txtKraj.Text; p.Vreme = txtVreme.Text; refreshLBX(); }
public void PrikaziPotez(Potez p) { if (_tabla[p.Pozicija.X, p.Pozicija.Y].BackgroundImage != null) { return; } _tabla[p.Pozicija.X, p.Pozicija.Y].BackgroundImage = p.PostavljenaFigura.Slika; _tabla[p.Pozicija.X, p.Pozicija.Y].Posecivano = true; ProvidnoDugme pd = DajDugmePoSlici(p.PostavljenaFigura.Slika); //figura za izbor if (pd != null) { pd.Posecivano = true; pd.BackgroundImage = null; _selektovano.BackgroundImage = null; } }
private void btnDodajPotez_Click(object sender, EventArgs e) { if (txtPoc.Text == "" || txtKraj.Text == "" || txtVreme.Text == "") { MessageBox.Show("Popunite sva polja"); return; } Potez p = new Potez(); p.RedniBr = Ptz.Count() + 1; p.PocetnoPolje = txtPoc.Text; p.KrajnjePolje = txtKraj.Text; p.Vreme = txtVreme.Text; Ptz.Add(p); refreshLBX(); }
private void Button36_Click(object sender, EventArgs e) { try { ISession s = DataLayer.GetSession(); Sahovska_Federacija.Entiteti.Sahovski_turnir t = s.Load <Sahovska_Federacija.Entiteti.Sahovski_turnir>(7); Partija p = new Partija(); p.bele = "Charles Mangus"; p.crne = "Milos Perunovic"; p.kad_se_igra = "18.3.2000. 13:30"; p.trajanje = 15; p.pat = "N"; p.mat = "Y"; p.rem = "N"; p.IgraSe = t; s.Save(p); t.Partije.Add(p); s.Save(t); Potez m = new Potez(); m.opis = "beli top na polju D4"; m.kad_odigran = "13:32"; m.je_odigran = p; s.Save(m); p.Potezi.Add(m); s.Save(p); s.Close(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
private void btnObrisiPotez_Click(object sender, EventArgs e) { if (lstPotez.Items.Count == 0) { return; } try { ISession s = DataLayer.GetSession(); Potez p = (Potez)lstPotez.Items[lstPotez.Items.Count - 1]; Ptz.Remove(p); s.Delete(p); s.Flush(); s.Close(); refreshLBX(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
void b_Click(object sender, EventArgs e) { Button b = sender as Button; if (b == null) { return; } int x = (int)b.Tag; int y = x % 10; x = x / 10; UradiPotez(new Potez() { x = x, y = y, }); if (context.NaPotezu != igrac) { try { this.Enabled = false; if (context.TrenutnoStanje.DoKraja() == 0) { MessageBox.Show("Nerešeno"); return; } Potez p = ContextIksOks.MinMax(context, 8); UradiPotez(p); } finally { this.Enabled = true; } } }
private void Button1_Click(object sender, EventArgs e) { int partijaId = Int32.Parse(listView1.SelectedItems[0].SubItems[0].Text); ISession s = DataLayer.GetSession(); Sahovska_Federacija.Entiteti.Partija partija = s.Load <Sahovska_Federacija.Entiteti.Partija>(partijaId); Potez potez = new Potez(); potez.opis = richTextBox1.Text; potez.kad_odigran = textBox1.Text; if (listView1.SelectedItems.Count == 0) { MessageBox.Show("Odaberite partiju!"); return; } potez.je_odigran = partija; s.Save(potez); partija.Potezi.Add(potez); s.Save(partija); MessageBox.Show("Uspesno ste dodali potez!"); }
public async Task <IActionResult> BaciKocku() { string igraId = User.FindFirstValue("sub"); Boja bojaIgraca = Enum.Parse <Boja>(User.FindFirstValue("Boja")); Igra game = await GameProvider.NadjiIgruFigure(db, igraId); if (game == null) { return(NotFound()); } if (game.status != statusIgre.uToku || game.naPotezu != bojaIgraca || game.aleaIactaEst) { return(Forbid()); } int vrKocke = Igra.generisiKocku(); Potez noviPotez = new Potez(game, vrKocke, bojaIgraca); await GameProvider.dodajPotez(db, noviPotez); game.aleaIactaEst = !game.aleaIactaEst; bool next = false; if (!game.imaLiSeStaOdigrati(bojaIgraca, vrKocke)) { if (vrKocke != 6) { next = true; game.naPotezu = (Igra.redosledPoteza.Find(bojaIgraca).Next ?? Igra.redosledPoteza.First).Value; } game.aleaIactaEst = !game.aleaIactaEst; } await GameProvider.AzurirajIgru(db, game); await GameHubHelper.kockaBacenaNotifyAsync(_gameHub, game.groupNameGUID, vrKocke, next); return(Ok()); }
private void PotezAi() { { //Ostali potezi Stopwatch sw = new Stopwatch(); sw.Start(); int[,] tabla = new int[4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { tabla[i, j] = _model.ReprezentacijaTableBrojevima()[i, j]; } } _kreiranjeListePoteza = 0; Potez p = AlphaBeta(tabla, 2, int.MinValue, int.MaxValue, 1); sw.Stop(); //MessageBox.Show("Vreme izvrsenja AlphaBeta algoritma: "+sw.Elapsed.TotalSeconds.ToString()); //MessageBox.Show("Vreme kreiranja liste poteza" + _kreiranjeListePoteza); _model.PostaviSelektovanu(p.PostavljenaFigura); _model.ZauzmiPolje(p.Pozicija.X, p.Pozicija.Y); _view.PrikaziPotez(p); if (KrajIgre()) { _view.Nereseno(); return; } _view.AzurirajPoruku(_model.TrenutniIgrac()); if (DaLijeNekoPobedio()) { _view.Pobeda(); } _model.SledeciIgrac(); } }
private Potez AlphaBeta(int[,] polje, int depth, int alpha, int beta, int max) { string kljuc = TranspozicionaTabela.Hash(polje); Unos unos = TranspozicionaTabela.DajUnos(kljuc); if (unos != null) { if (unos.Dubina == depth) { return(unos.NajboljiPotez); } } //Stopwatch sw = new Stopwatch(); // sw.Start(); var c = ListaMogucihPoteza(polje); //sw.Stop(); //_kreiranjeListePoteza += sw.Elapsed.TotalSeconds; if (depth == 0 || c.Count == 0) { int ca = Evaluacija(polje); return(new Potez() { Value = ca }); } Potez najbolji = new Potez(); if (max == 1) { najbolji.Value = int.MinValue; foreach (var p in c) { polje[p.Pozicija.X, p.Pozicija.Y] = p.PostavljenaFigura.ReprezentacijaBrojem(); p.PostavljenaFigura.Iskoriscena = true; Potez tmp = AlphaBeta(polje, depth - 1, alpha, beta, 0); polje[p.Pozicija.X, p.Pozicija.Y] = -1; p.PostavljenaFigura.Iskoriscena = false; p.Value = tmp.Value; if (p.Value > najbolji.Value) { najbolji = p; } alpha = Math.Max(alpha, najbolji.Value); if (alpha >= beta) { break; } } } else { najbolji.Value = int.MaxValue; foreach (var p in c) { polje[p.Pozicija.X, p.Pozicija.Y] = p.PostavljenaFigura.ReprezentacijaBrojem(); p.PostavljenaFigura.Iskoriscena = true; Potez tmp = AlphaBeta(polje, depth - 1, alpha, beta, 1); polje[p.Pozicija.X, p.Pozicija.Y] = -1; p.PostavljenaFigura.Iskoriscena = false; p.Value = tmp.Value; if (p.Value < najbolji.Value) { najbolji = p; } beta = Math.Min(beta, najbolji.Value); if (alpha >= beta) { break; } } } Unos tmpUnos = TranspozicionaTabela.DajUnos(kljuc); if (tmpUnos == null) { tmpUnos = new Unos() { Alfa = alpha, Beta = beta, Dubina = depth, NajboljiPotez = najbolji }; TranspozicionaTabela.DodajUnos(kljuc, tmpUnos); } else { tmpUnos.Dubina = depth; tmpUnos.Alfa = alpha; tmpUnos.Beta = beta; tmpUnos.NajboljiPotez = najbolji; } return(najbolji); }
private void btnTppC_Click(object sender, EventArgs e) { try { ISession s = DataLayer.GetSession(); TurnirTakmicarskiRegionalni p = new TurnirTakmicarskiRegionalni(); p.Naziv = "Morlat Vombat"; p.DatumOd = new DateTime(2001, 6, 21); p.DatumDo = new DateTime(2001, 6, 24); p.Drzava = "Kanada"; p.Godina = 2001; p.Grad = "Otawa"; p.NacinOdigravanja = "NORMALAN"; s.SaveOrUpdate(p); Partija j = new Partija(); j.Ishod = "REMI"; j.Trajanje = 32323; j.Vreme = "56:27"; j.Datum = new DateTime(2001, 6, 24); j.BeliIgrac = s.Load <Sahista>(1007); j.CrniIgrac = s.Load <Sahista>(1008); j.Sudija = s.Load <Sudija>(103); j.Turnir = p; s.SaveOrUpdate(j); Potez k1 = new Potez(); k1.KrajnjePolje = "a8"; k1.PocetnoPolje = "g7"; k1.RedniBr = 1; k1.Vreme = "01:11"; k1.Partija = j; s.SaveOrUpdate(k1); Potez k2 = new Potez(); k2.KrajnjePolje = "c4"; k2.PocetnoPolje = "h3"; k2.RedniBr = 2; k2.Vreme = "57"; k2.Partija = j; s.SaveOrUpdate(k2); Potez k3 = new Potez(); k3.KrajnjePolje = "e1"; k3.PocetnoPolje = "d7"; k3.RedniBr = 3; k3.Vreme = "024"; k3.Partija = j; s.SaveOrUpdate(k3); s.Flush(); s.Close(); MessageBox.Show("Uspesno ubacen turnir sa partijama"); } catch (Exception ec) { MessageBox.Show(ec.Message); MessageBox.Show("Desila se greska"); } }
public static async Task dodajPotez(DontGetSpicyContext db, Potez noviPotez) { db.Potezi.Add(noviPotez); await db.SaveChangesAsync(); }
// POST: api/Potez public int Post([FromBody] Potez value) { DataProvider dp = new DataProvider(); return(dp.AddPotez(value)); }
public static async Task AzurirajPotez(DontGetSpicyContext db, Potez potez) { db.Potezi.Update(potez); await db.SaveChangesAsync(); }
//POST: api/potez/id_partije public int Post(int id, [FromBody] Potez bp) { DTOManager manager = new DTOManager(); return(manager.DodajPotez(bp.opis, bp.kad_odigran, id)); }