Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:



Algoritmus pro zjištění koroktnosti tahu u deskové hry

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: grafnev

16:07:40 03.11.2009

Strucne jeste (nejsem si jist, ze to mam spravne :):

skok - jeden pohyb
tah - serie pohybu

Prochazeni do hloubky:
0) Vzdy si pamatuj nelepsi tah a soucasny tah
1) Vem plochu a uloz vsechny mozne skoky na ZASOBNIK
2) Jestli je zasobnik prazdny tak mam ulozen nejlepsi tah, jinak
3) Vezmi skok ze zasobniku
4) Vrat se se soucasnym tahem pred tento skok
5) Proved skok a pokracuj od bodu 1

Prochazeni do sirky (vsimni si copy and paste):
0) Vzdy si pamatuj nelepsi tah a soucasny tah
1) Vem plochu a uloz vsechny mozne skoky do FRONTY
2) Jestli je zasobnik prazdny tak mam ulozen nejlepsi tah, jinak
3) Vezmi skok ze zasobniku
4) Vrat se se soucasnym tahem pred tento skok
5) Proved skok a pokracuj od bodu 1

Rekurzivni prochazeni do hloubky:
funkce ProjdiVsechnyTahy(naTetoPlose, cesta)
{
pro vsechny skoky SKOK proved {
novaPlocha=provedTah(naTetoPlose,SKOK);
ProjdiVsechnyTahy(naTetoPlose, cesta + SKOK);
}
vypisCestu(cesta);
}

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: grafnev

15:49:17 03.11.2009

Urcite bude neco takoveho v programech, ale problem je klasicke prochazeni nejakeho stavoveho prostoru. Takze lze prochazet do hloubky a do sirky + existuji na to nejake standardni algoritmy, ktere nejsou hruba sila, pak lze pouzit specificke vlastnosti ulohy a jeste to omezit:

Pokud se chces ucit, tak bych udelal sproste prochazeni bez optimalizace ... naucis se jak to funguje, jak udelat omezujici podminky (aby ti to neskakalo dokolecka atd.).

Pak se muzes vrhnout na dalsi veci.

[ital]To Maaartin:V podstatě potřebuji hledat v grafu nejdelší cestu,ale neznám algoritmus co by to uměl.Pokud bych to dělal pomocí průchodu grafu tak bych nejspíš musel najít všechny cesty a znich vybrat tu nejdelší[/ital]

Presne tak ... prochazeni do hloubky nebo do sirky a presne tak ... vyberes si nejdelsi cestu kterou najdes ...

Teorii mas tu: http://cs.wikipedia.org/wiki/Prohled%C3%A1v%C3%A1n%C3%AD_do_hloubky (i v tech spriznenych odkazech a pod) ...

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: tcesky

8:37:35 03.11.2009

[ital]Tak nějak sem to napsal Tc-mu,že si to chci napsat sám. Jeho kód má určitě vysokou kvalitu ,ale já to nechtěl vypracovat spíš sem chtěl jen posbírat nějaké rady. [/ital]

To co sem napsal ma kvalitu velice pofiderni ale demonstruje to moznou techniku reseni problemu na ktery jsi se ptal. Staci si to poradne precist (jsem si vedom ze ne vsichni jsou schopni porozumet psanemu textu), poucit se a pak si to napsat poradne.

Zdravim
TC

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Lama

23:48:30 02.11.2009

Mi.Chal Napsal:
-------------------------------------------------------
> Lama Napsal:
> --------------------------------------------------
> -----
> > Nemůžu ten zdroják celý přečíst je tam pro
> mě
> > nějaká neznámá syntaxe jaký je to jazyk?
>
> C#
>
> Jestli to chces v C++, tak zkus napsat do diskuze
> C/C++, ze to mas jako domaci ukol a skola te
> vlastne vubec nebavi, na to TC vetsinou nejaky
> zdrojak vysmahne. Ale pokud chces pochopit jak to
> funguje, tak je jednodussi si to napsat sam .
>
>
>
>
> ________________________________________________
> Odpovedi na nejcastejsi zdejsi otazky najdete na
> http://www.4itdevelopers.net/faq_at_builder.aspx

> >

Tak nějak sem to napsal Tc-mu,že si to chci napsat sám. Jeho kód má určitě vysokou kvalitu ,ale já to nechtěl vypracovat spíš sem chtěl jen posbírat nějaké rady.

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Mi.Chal

23:36:39 02.11.2009

Lama Napsal:
-------------------------------------------------------
> Nemůžu ten zdroják celý přečíst je tam pro mě
> nějaká neznámá syntaxe jaký je to jazyk?

C#

Jestli to chces v C++, tak zkus napsat do diskuze C/C++, ze to mas jako domaci ukol a skola te vlastne vubec nebavi, na to TC vetsinou nejaky zdrojak vysmahne. Ale pokud chces pochopit jak to funguje, tak je jednodussi si to napsat sam :-).

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Lama

22:03:10 02.11.2009

Nemůžu ten zdroják celý přečíst je tam pro mě nějaká neznámá syntaxe jaký je to jazyk?

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: tcesky

21:05:27 02.11.2009

[ital] V podstatě potřebuji hledat v grafu nejdelší cestu,ale neznám algoritmus co by to uměl.Pokud bych to dělal pomocí průchodu grafu tak bych nejspíš musel najít všechny cesty a znich vybrat tu nejdelší.[/ital] viz: http://forum.builder.cz/read.php?13,3151794,3158492#msg-3158492

[ital]jen mě mrzí ,že nemám čas zjistit jak jeho kód funguje[/ital] Kdyz nemas cas tak nic nedelej.

Zdravim

TC

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Lama

18:50:26 02.11.2009

Ahoj,
děkuji panu TC jen mě mrzí ,že nemám čas zjistit jak jeho kód funguje myslím,že budu mít rychlejší když se pokusím něco splácat sám a taky se u toho víc naučím.

To Maaartin:V podstatě potřebuji hledat v grafu nejdelší cestu,ale neznám algoritmus co by to uměl.Pokud bych to dělal pomocí průchodu grafu tak bych nejspíš musel najít všechny cesty a znich vybrat tu nejdelší.

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: tcesky

18:09:07 01.11.2009

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;
[/color][color=#0000ff]using[/color][color=#000000] System.IO;
[/color][color=#0000ff]using[/color][color=#000000] RouteEngine; [/color][color=#008000]// http://www.codeproject.com/KB/recipes/ShortestPathCalculation.aspx


[/color][color=#0000ff]namespace[/color][color=#000000] NewbieDesktop
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]


[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Shortest path approach
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Sample result:
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Shortest connection B0 - B4
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] B0 - B2
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] B2 - B4
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Drücken Sie eine beliebige Taste . . .
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program
[/color][color=#000000] {
[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args)
{
[/color][color=#0000ff]var[/color][color=#000000] desk = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Newbie[/color][color=#000000]();
desk.Add([/color][color=#a31515]"B1"[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000].Black);
desk.Add([/color][color=#a31515]"B3"[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000].Black);
desk.Add([/color][color=#a31515]"C3"[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000].White);

desk.Calculate([/color][color=#a31515]"B0"[/color][color=#000000], [/color][color=#a31515]"B4"[/color][color=#000000]);
[/color][color=#2b91af]Location[/color][color=#000000] loc = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Location[/color][color=#000000]();
loc.Identifier = [/color][color=#a31515]"aaa"[/color][color=#000000];
}
}

[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Newbie[/color][color=#000000] : [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000]>
{
[/color][color=#0000ff]const[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] dimension = 8;
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]enum[/color][color=#000000] [/color][color=#2b91af]Color[/color][color=#000000] { Black, White }
[/color][color=#0000ff]public[/color][color=#000000] Newbie() : [/color][color=#0000ff]base[/color][color=#000000]() { }

[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Find path from p1 to p2
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]starting position[/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]target position[/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]both positions must be vacant to be eligible for the connection[/color][color=#808080]
[/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Calculate([/color][color=#0000ff]string[/color][color=#000000] p1, [/color][color=#0000ff]string[/color][color=#000000] p2)
{

[/color][color=#0000ff]var[/color][color=#000000] conn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Connection[/color][color=#000000]>();
[/color][color=#0000ff]var[/color][color=#000000] loc = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Location[/color][color=#000000]>();
[/color][color=#0000ff]var[/color][color=#000000] lst = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000]>();

[/color][color=#008000]// First identify all connections
[/color][color=#000000] [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++)
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++)
{
[/color][color=#0000ff]var[/color][color=#000000] src = Pos(i, j);

[/color][color=#0000ff]if[/color][color=#000000] (!ContainsKey(src)) [/color][color=#008000]// source must be vacant
[/color][color=#000000] {
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i1 = 0; i1 < 2; i1++)
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j1 = 0; j1 < 2; j1++)
{
[/color][color=#0000ff]var[/color][color=#000000] interim = Pos(i + i1, j + j1);
[/color][color=#0000ff]var[/color][color=#000000] trg = Pos(i + 2 * i1, j + 2 * j1);
[/color][color=#0000ff]if[/color][color=#000000] (ContainsKey(interim) && !ContainsKey(trg))
{
[/color][color=#0000ff]int[/color][color=#000000] ind = lst.BinarySearch(trg);
[/color][color=#0000ff]if[/color][color=#000000] (ind < 0) lst.Insert(~ind, trg);
ind = lst.BinarySearch(src);
[/color][color=#0000ff]if[/color][color=#000000] (ind < 0) lst.Insert(~ind, src);
}
}
}
}

[/color][color=#008000]// Then build connection
[/color][color=#000000] [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]string[/color][color=#000000] str [/color][color=#0000ff]in[/color][color=#000000] lst) { [/color][color=#0000ff]var[/color][color=#000000] lo = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Location[/color][color=#000000](); lo.Identifier = str; loc.Add(lo); }
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++)
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++)
{
[/color][color=#0000ff]var[/color][color=#000000] src = Pos(i, j);

[/color][color=#0000ff]if[/color][color=#000000] (!ContainsKey(src)) [/color][color=#008000]// source must be vacant
[/color][color=#000000] {
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i1 = 0; i1 < 2; i1++)
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j1 = 0; j1 < 2; j1++)
{
[/color][color=#0000ff]var[/color][color=#000000] interim = Pos(i + i1, j + j1);
[/color][color=#0000ff]var[/color][color=#000000] trg = Pos(i + 2 * i1, j + 2 * j1);
[/color][color=#0000ff]if[/color][color=#000000] (ContainsKey(interim) && !ContainsKey(trg))
{
[/color][color=#0000ff]int[/color][color=#000000] srcInd = lst.BinarySearch(src);
[/color][color=#0000ff]int[/color][color=#000000] trgInd = lst.BinarySearch(trg);
conn.Add([/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Connection[/color][color=#000000](loc[[/color][color=#000000]srcInd], loc[[/color][color=#000000]trgInd], 1));
}
}
}
}

[/color][color=#0000ff]int[/color][color=#000000] indP1 = lst.BinarySearch(p1);
[/color][color=#0000ff]int[/color][color=#000000] indP2 = lst.BinarySearch(p2);
[/color][color=#2b91af]Console[/color][color=#000000].WriteLine([/color][color=#a31515]"Shortest connection {0} - {1}"[/color][color=#000000], p1, p2);
[/color][color=#0000ff]if[/color][color=#000000] (indP1 < 0 || indP2 < 0) [/color][color=#2b91af]Console[/color][color=#000000].WriteLine([/color][color=#a31515]"Can not jump"[/color][color=#000000]);
[/color][color=#0000ff]else
[/color][color=#000000] {
[/color][color=#0000ff]var[/color][color=#000000] re = [/color][color=#0000ff]new[/color][color=#000000] RouteEngine.[/color][color=#2b91af]RouteEngine[/color][color=#000000]();


re.Locations.AddRange(loc);
re.Connections.AddRange(conn);
[/color][color=#0000ff]var[/color][color=#000000] routes = re.CalculateMinCost(loc[[/color][color=#000000]indP1]);

[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] route [/color][color=#0000ff]in[/color][color=#000000] routes)
{
[/color][color=#0000ff]if[/color][color=#000000] (route.Key == loc[[/color][color=#000000]indP2])
{
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] co [/color][color=#0000ff]in[/color][color=#000000] route.Value.Connections)
[/color][color=#2b91af]Console[/color][color=#000000].WriteLine([/color][color=#a31515]"{0} - {1}"[/color][color=#000000], co.A, co.B);
}
}
}
}
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Indices to code
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]index[/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]index[/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]code[/color][color=#808080]
[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] Pos([/color][color=#0000ff]int[/color][color=#000000] i, [/color][color=#0000ff]int[/color][color=#000000] j) { [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000].Format([/color][color=#a31515]"{0}{1}"[/color][color=#000000], ([/color][color=#0000ff]char[/color][color=#000000])([/color][color=#a31515]'A'[/color][color=#000000] + i), ([/color][color=#0000ff]char[/color][color=#000000])([/color][color=#a31515]'0'[/color][color=#000000] + j)); }
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Just for future
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]string to parse[/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]resulting index[/color][color=#808080]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]resulting index[/color][color=#808080]
[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Pos([/color][color=#0000ff]string[/color][color=#000000] str, [/color][color=#0000ff]out[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] i, [/color][color=#0000ff]out[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] j)
{
i = -1;
j = -1;
[/color][color=#0000ff]if[/color][color=#000000] (str.Length != 2) [/color][color=#0000ff]return[/color][color=#000000];
i = str[[/color][color=#000000]0] - [/color][color=#a31515]'A'[/color][color=#000000];
j = str[[/color][color=#000000]1] - [/color][color=#a31515]'0'[/color][color=#000000];
}
}
}
[/color][/code]
[size=10px]Produkt lepiče kódu[/size]


Zdravim
TC

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Shortest path approach [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Sample result: [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Shortest connection B0 - B4 [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] B0 - B2 [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] B2 - B4 [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Drücken Sie eine beliebige Taste . . . [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program [/color][color=#000000] { [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args) { [/color][color=#0000ff]var[/color][color=#000000] desk = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Newbie[/color][color=#000000](); desk.Add([/color][color=#a31515]"B1"[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000].Black); desk.Add([/color][color=#a31515]"B3"[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000].Black); desk.Add([/color][color=#a31515]"C3"[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000].White); desk.Calculate([/color][color=#a31515]"B0"[/color][color=#000000], [/color][color=#a31515]"B4"[/color][color=#000000]); [/color][color=#2b91af]Location[/color][color=#000000] loc = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Location[/color][color=#000000](); loc.Identifier = [/color][color=#a31515]"aaa"[/color][color=#000000]; } } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Newbie[/color][color=#000000] : [/color][color=#2b91af]Dictionary[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000], [/color][color=#2b91af]Newbie[/color][color=#000000].[/color][color=#2b91af]Color[/color][color=#000000]> { [/color][color=#0000ff]const[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] dimension = 8; [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]enum[/color][color=#000000] [/color][color=#2b91af]Color[/color][color=#000000] { Black, White } [/color][color=#0000ff]public[/color][color=#000000] Newbie() : [/color][color=#0000ff]base[/color][color=#000000]() { } [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Find path from p1 to p2 [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]starting position[/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]target position[/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]both positions must be vacant to be eligible for the connection[/color][color=#808080] [/color][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Calculate([/color][color=#0000ff]string[/color][color=#000000] p1, [/color][color=#0000ff]string[/color][color=#000000] p2) { [/color][color=#0000ff]var[/color][color=#000000] conn = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Connection[/color][color=#000000]>(); [/color][color=#0000ff]var[/color][color=#000000] loc = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]Location[/color][color=#000000]>(); [/color][color=#0000ff]var[/color][color=#000000] lst = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#0000ff]string[/color][color=#000000]>(); [/color][color=#008000]// First identify all connections [/color][color=#000000] [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++) [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++) { [/color][color=#0000ff]var[/color][color=#000000] src = Pos(i, j); [/color][color=#0000ff]if[/color][color=#000000] (!ContainsKey(src)) [/color][color=#008000]// source must be vacant [/color][color=#000000] { [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i1 = 0; i1 < 2; i1++) [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j1 = 0; j1 < 2; j1++) { [/color][color=#0000ff]var[/color][color=#000000] interim = Pos(i + i1, j + j1); [/color][color=#0000ff]var[/color][color=#000000] trg = Pos(i + 2 * i1, j + 2 * j1); [/color][color=#0000ff]if[/color][color=#000000] (ContainsKey(interim) && !ContainsKey(trg)) { [/color][color=#0000ff]int[/color][color=#000000] ind = lst.BinarySearch(trg); [/color][color=#0000ff]if[/color][color=#000000] (ind < 0) lst.Insert(~ind, trg); ind = lst.BinarySearch(src); [/color][color=#0000ff]if[/color][color=#000000] (ind < 0) lst.Insert(~ind, src); } } } } [/color][color=#008000]// Then build connection [/color][color=#000000] [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]string[/color][color=#000000] str [/color][color=#0000ff]in[/color][color=#000000] lst) { [/color][color=#0000ff]var[/color][color=#000000] lo = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Location[/color][color=#000000](); lo.Identifier = str; loc.Add(lo); } [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++) [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++) { [/color][color=#0000ff]var[/color][color=#000000] src = Pos(i, j); [/color][color=#0000ff]if[/color][color=#000000] (!ContainsKey(src)) [/color][color=#008000]// source must be vacant [/color][color=#000000] { [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i1 = 0; i1 < 2; i1++) [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j1 = 0; j1 < 2; j1++) { [/color][color=#0000ff]var[/color][color=#000000] interim = Pos(i + i1, j + j1); [/color][color=#0000ff]var[/color][color=#000000] trg = Pos(i + 2 * i1, j + 2 * j1); [/color][color=#0000ff]if[/color][color=#000000] (ContainsKey(interim) && !ContainsKey(trg)) { [/color][color=#0000ff]int[/color][color=#000000] srcInd = lst.BinarySearch(src); [/color][color=#0000ff]int[/color][color=#000000] trgInd = lst.BinarySearch(trg); conn.Add([/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Connection[/color][color=#000000](loc[[/color][color=#000000]srcInd], loc[[/color][color=#000000]trgInd], 1)); } } } } [/color][color=#0000ff]int[/color][color=#000000] indP1 = lst.BinarySearch(p1); [/color][color=#0000ff]int[/color][color=#000000] indP2 = lst.BinarySearch(p2); [/color][color=#2b91af]Console[/color][color=#000000].WriteLine([/color][color=#a31515]"Shortest connection {0} - {1}"[/color][color=#000000], p1, p2); [/color][color=#0000ff]if[/color][color=#000000] (indP1 < 0 || indP2 < 0) [/color][color=#2b91af]Console[/color][color=#000000].WriteLine([/color][color=#a31515]"Can not jump"[/color][color=#000000]); [/color][color=#0000ff]else [/color][color=#000000] { [/color][color=#0000ff]var[/color][color=#000000] re = [/color][color=#0000ff]new[/color][color=#000000] RouteEngine.[/color][color=#2b91af]RouteEngine[/color][color=#000000](); re.Locations.AddRange(loc); re.Connections.AddRange(conn); [/color][color=#0000ff]var[/color][color=#000000] routes = re.CalculateMinCost(loc[[/color][color=#000000]indP1]); [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] route [/color][color=#0000ff]in[/color][color=#000000] routes) { [/color][color=#0000ff]if[/color][color=#000000] (route.Key == loc[[/color][color=#000000]indP2]) { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] co [/color][color=#0000ff]in[/color][color=#000000] route.Value.Connections) [/color][color=#2b91af]Console[/color][color=#000000].WriteLine([/color][color=#a31515]"{0} - {1}"[/color][color=#000000], co.A, co.B); } } } } [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Indices to code [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]index[/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]index[/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]code[/color][color=#808080] [/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] Pos([/color][color=#0000ff]int[/color][color=#000000] i, [/color][color=#0000ff]int[/color][color=#000000] j) { [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000].Format([/color][color=#a31515]"{0}{1}"[/color][color=#000000], ([/color][color=#0000ff]char[/color][color=#000000])([/color][color=#a31515]'A'[/color][color=#000000] + i), ([/color][color=#0000ff]char[/color][color=#000000])([/color][color=#a31515]'0'[/color][color=#000000] + j)); } [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Just for future [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]string to parse[/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]resulting index[/color][color=#808080] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080][/color][color=#008000]resulting index[/color][color=#808080] [/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Pos([/color][color=#0000ff]string[/color][color=#000000] str, [/color][color=#0000ff]out[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] i, [/color][color=#0000ff]out[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] j) { i = -1; j = -1; [/color][color=#0000ff]if[/color][color=#000000] (str.Length != 2) [/color][color=#0000ff]return[/color][color=#000000]; i = str[[/color][color=#000000]0] - [/color][color=#a31515]'A'[/color][color=#000000]; j = str[[/color][color=#000000]1] - [/color][color=#a31515]'0'[/color][color=#000000]; } } } [/color][/code] [size=10px]Produkt lepiče kódu[/size] Zdravim TC

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Maaartin

14:34:12 01.11.2009

> [ital]A nepotrebujes nahodou iba algoritmus, co ti najde najdlhsiu cestu? Cim dlhsia, tym viac superovych figurok vypadne a o to predsa ide, nie?[/ital]

Noooo.... vetsinou to muze byt nejlepsi ale urcite ne vzdy. Pokud to neni v pravidlech ze se musi skakat jak o dusu, tak to takhle nepujde - ani pro kontrolu spravnosti tahu ani pro slusny hrani.

> [ital]Ahoj, ten článek o šachu je docela zajímavý,ale až moc se týká konkrétně šachů (které jsme nikdy nehrál a neznám pravidla takže z něj až tolik nepochytím).[/ital]

Taxe je nauc - pokud jde o deskovy hry tak k zadny nenajdes tolik informaci jako prave k sachum. A nauceni se celych pravidel je na par minut.

> [ital]Každopádně přehodnotil jsme můj původní dotaz týkající se jednoduchého přeskoku na to,že potřebuji přeskok složený.A abych jej mohl realizovat tak potřebuji algoritmus co najde všechny cesty z jednoho místa do druhého místa.Nevíte jak se takový algoritmus jmenuje??[/ital]

Podobnych je hafo, ale odhaduju ze co potrebujes je jednoduchy prochazeni grafu - hledani do sirky co do hloubky
http://en.wikipedia.org/wiki/Breadth-first_search
Pokud tomu nerozumis, taxnad pomuzou obrazky. Do algoritmu typu nejkratsi/nejdelsi cesta bych se nepoustel, je dobry je umet, ale mam pocit ze tvuj problem neresi.

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: tcesky

12:59:49 01.11.2009

[code]
[color=#0000ff]using[/color][color=#000000] System;
[/color][color=#0000ff]using[/color][color=#000000] System.Collections.Generic;
[/color][color=#0000ff]using[/color][color=#000000] System.Linq;
[/color][color=#0000ff]using[/color][color=#000000] System.Text;
[/color][color=#0000ff]using[/color][color=#000000] System.Drawing;

[/color][color=#0000ff]namespace[/color][color=#000000] LamaDesk
{
[/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]


[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Ahoj,pustil jsme se do programování deskové hry a ctěl bych se zeptat jak naprogragramovat
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] algoritmus pro ověření tahu.(programuji v C++)
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Hrací pole je 8x8 figurky můžou jen skákat přez své i protivníkovy figurky pohyb je povolen pouze
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] pomocí přeskoků,přeskoky mohou být vícenásobné a figurky mohou skákat v ortogonálním i
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] diagonálním směru.
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Prozatím mě napadlo v závislosti na tom jaké jsou souřadnice zdrojové figurky a cílového místa
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] zjistit směr, kterým by se zdrojová figurka měla vydat.
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Něco jako ,že když Xzf == Xcm (zf zdrojova ,cf cilove místo) tak vím ,že figurka by se měla na
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] desce vydat nahoru nebo dolů.Jestli nahoru nebo dolů bych rozhodl na základě vyhodnocení
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Yzf a Ycm. Pokud Yzf > Ycm tak vím ,že figurka se má vydat směrem dolů.
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Je to triviální vyhodnocení několika podmínek a proto bych se chtěl zeptat jestli je to
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] použitelné nebo jestli víte o něčem lepším.
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Děkuji vám :)
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000]
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Beginer
[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080]

[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program
[/color][color=#000000] {
[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args)
{
[/color][color=#0000ff]var[/color][color=#000000] sample = [/color][color=#2b91af]LamaDeskGame[/color][color=#000000].TestSample();
[/color][color=#2b91af]Console[/color][color=#000000].Write(sample);
TryNext(sample, [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000](0, 1), [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000](4, 1));
}

[/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] TryNext([/color][color=#2b91af]LamaDeskGame[/color][color=#000000] game, [/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Point[/color][color=#000000] trg)
{
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#2b91af]LamaDeskGame[/color][color=#000000].[/color][color=#2b91af]Dir[/color][color=#000000] dir [/color][color=#0000ff]in[/color][color=#000000] [/color][color=#2b91af]Enum[/color][color=#000000].GetValues([/color][color=#0000ff]typeof[/color][color=#000000]([/color][color=#2b91af]LamaDeskGame[/color][color=#000000].[/color][color=#2b91af]Dir[/color][color=#000000])))
{
[/color][color=#0000ff]var[/color][color=#000000] gm = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame[/color][color=#000000](game, src, dir);
[/color][color=#0000ff]if[/color][color=#000000] (gm.OK)
{
[/color][color=#0000ff]if[/color][color=#000000] (gm.current == trg) [/color][color=#2b91af]Console[/color][color=#000000].Write(gm);
[/color][color=#0000ff]else[/color][color=#000000] TryNext(gm, gm.current, trg);
}
}
}
}

[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame
[/color][color=#000000] {
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]LamaDeskGame[/color][color=#000000]> history;

[/color][color=#0000ff]const[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] dimension = 8;
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]enum[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000] { None, White, Black }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]enum[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000] { N, E, S, W, NE, SE, NW, SW };
[/color][color=#2b91af]Pawn[/color][color=#000000][[/color][color=#000000],] desk;
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]bool[/color][color=#000000] OK;
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000] current;

[/color][color=#2b91af]Point[/color][color=#000000] startPoint;
[/color][color=#2b91af]Dir[/color][color=#000000] startDir;

[/color][color=#0000ff]bool[/color][color=#000000] Dejavu([/color][color=#2b91af]LamaDeskGame[/color][color=#000000] g) { [/color][color=#0000ff]return[/color][color=#000000] g.startPoint == startPoint && g.startDir == startDir; }
[/color][color=#0000ff]public[/color][color=#000000] LamaDeskGame()
{
desk = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000][[/color][color=#000000]dimension, dimension];
OK = [/color][color=#0000ff]true[/color][color=#000000];
history = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]LamaDeskGame[/color][color=#000000]>();
current = [/color][color=#2b91af]Point[/color][color=#000000].Empty;
}
[/color][color=#0000ff]public[/color][color=#000000] LamaDeskGame([/color][color=#2b91af]LamaDeskGame[/color][color=#000000] game, [/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir)
: [/color][color=#0000ff]this[/color][color=#000000]()
{
startPoint = src;
startDir = dir;
[/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] g [/color][color=#0000ff]in[/color][color=#000000] game.history)
[/color][color=#0000ff]if[/color][color=#000000] (Dejavu(g))
{
OK = [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]return[/color][color=#000000];
}
history.AddRange(game.history);
history.Add(game);
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++)
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++)
desk[[/color][color=#000000]i, j] = game.desk[[/color][color=#000000]i, j];
OK = CanMove(src, dir);
[/color][color=#0000ff]if[/color][color=#000000] (OK) Move(src, dir);
}
[/color][color=#0000ff]bool[/color][color=#000000] Target([/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir, [/color][color=#0000ff]out[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000] trg)
{
trg = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000](src.X, src.Y);
[/color][color=#0000ff]switch[/color][color=#000000] (dir)
{
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].N: trg.Y++; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].E: trg.X++; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].S: trg.Y--; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].W: trg.X--; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].NE: trg.Y++; trg.X++; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].NW: trg.Y++; trg.X--; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].SE: trg.Y--; trg.X++; [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].SW: trg.Y--; trg.X--; [/color][color=#0000ff]break[/color][color=#000000];
}
[/color][color=#0000ff]if[/color][color=#000000] (trg.X < 0) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]if[/color][color=#000000] (trg.X >= dimension) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]if[/color][color=#000000] (trg.Y < 0) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]if[/color][color=#000000] (trg.Y >= dimension) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]true[/color][color=#000000];
}
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000] AtPos([/color][color=#2b91af]Point[/color][color=#000000] pt) { [/color][color=#0000ff]return[/color][color=#000000] desk[[/color][color=#000000]pt.X, pt.Y]; }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] ToPos([/color][color=#2b91af]Point[/color][color=#000000] pt, [/color][color=#2b91af]Pawn[/color][color=#000000] p) { desk[[/color][color=#000000]pt.X, pt.Y] = p; }
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]bool[/color][color=#000000] CanMove([/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir)
{
[/color][color=#0000ff]if[/color][color=#000000] (AtPos(src) == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#2b91af]Point[/color][color=#000000] trg;
[/color][color=#0000ff]if[/color][color=#000000] (!Target(src, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];

[/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]if[/color][color=#000000] (!Target(trg, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000];
[/color][color=#0000ff]return[/color][color=#000000] AtPos(trg) == [/color][color=#2b91af]Pawn[/color][color=#000000].None;
}
[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Move([/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir)
{
[/color][color=#0000ff]var[/color][color=#000000] pawn = AtPos(src);
[/color][color=#0000ff]if[/color][color=#000000] (pawn == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000]();
[/color][color=#2b91af]Point[/color][color=#000000] trg;
[/color][color=#0000ff]if[/color][color=#000000] (!Target(src, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000]();

[/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000]();
[/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) != pawn) ToPos(trg, [/color][color=#2b91af]Pawn[/color][color=#000000].None);
[/color][color=#0000ff]if[/color][color=#000000] (!Target(trg, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000]();
[/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) != [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000]();
ToPos(trg, pawn);
ToPos(src, [/color][color=#2b91af]Pawn[/color][color=#000000].None);
current = trg;
}

[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame[/color][color=#000000] TestSample()
{
[/color][color=#2b91af]Pawn[/color][color=#000000][[/color][color=#000000],] dsk ={
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].Black,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].Black,[/color][color=#2b91af]Pawn[/color][color=#000000].White,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].White,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None},
{[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}};
[/color][color=#0000ff]var[/color][color=#000000] sample = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame[/color][color=#000000]();
sample.desk = dsk;
[/color][color=#0000ff]return[/color][color=#000000] sample;
}

[/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]override[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] ToString()
{
[/color][color=#0000ff]var[/color][color=#000000] sb = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StringBuilder[/color][color=#000000]();
sb.AppendFormat([/color][color=#a31515]"{0} History: {1}"[/color][color=#000000], OK ? [/color][color=#a31515]"OK"[/color][color=#000000] : [/color][color=#a31515]"ERROR"[/color][color=#000000], history.Count);
sb.AppendLine();
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++)
{
[/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++)
[/color][color=#0000ff]switch[/color][color=#000000] (desk[[/color][color=#000000]i, j])
{
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000].None: sb.Append([/color][color=#a31515]" "[/color][color=#000000]); [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000].White: sb.Append([/color][color=#a31515]"W "[/color][color=#000000]); [/color][color=#0000ff]break[/color][color=#000000];
[/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000].Black: sb.Append([/color][color=#a31515]"B "[/color][color=#000000]); [/color][color=#0000ff]break[/color][color=#000000];
}
sb.AppendLine();
}
[/color][color=#0000ff]return[/color][color=#000000] sb.ToString();
}
}
}
[/color][/code]
[size=10px]Produkt lepiče kódu[/size]


Zdravim
TC

[/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Ahoj,pustil jsme se do programování deskové hry a ctěl bych se zeptat jak naprogragramovat [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] algoritmus pro ověření tahu.(programuji v C++) [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Hrací pole je 8x8 figurky můžou jen skákat přez své i protivníkovy figurky pohyb je povolen pouze [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] pomocí přeskoků,přeskoky mohou být vícenásobné a figurky mohou skákat v ortogonálním i [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] diagonálním směru. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Prozatím mě napadlo v závislosti na tom jaké jsou souřadnice zdrojové figurky a cílového místa [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] zjistit směr, kterým by se zdrojová figurka měla vydat. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Něco jako ,že když Xzf == Xcm (zf zdrojova ,cf cilove místo) tak vím ,že figurka by se měla na [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] desce vydat nahoru nebo dolů.Jestli nahoru nebo dolů bych rozhodl na základě vyhodnocení [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Yzf a Ycm. Pokud Yzf > Ycm tak vím ,že figurka se má vydat směrem dolů. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Je to triviální vyhodnocení několika podmínek a proto bych se chtěl zeptat jestli je to [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] použitelné nebo jestli víte o něčem lepším. [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Děkuji vám :) [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] Beginer [/color][color=#000000] [/color][color=#808080]///[/color][color=#008000] [/color][color=#808080] [/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]Program [/color][color=#000000] { [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Main([/color][color=#0000ff]string[/color][color=#000000][[/color][color=#000000]] args) { [/color][color=#0000ff]var[/color][color=#000000] sample = [/color][color=#2b91af]LamaDeskGame[/color][color=#000000].TestSample(); [/color][color=#2b91af]Console[/color][color=#000000].Write(sample); TryNext(sample, [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000](0, 1), [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000](4, 1)); } [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] TryNext([/color][color=#2b91af]LamaDeskGame[/color][color=#000000] game, [/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Point[/color][color=#000000] trg) { [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#2b91af]LamaDeskGame[/color][color=#000000].[/color][color=#2b91af]Dir[/color][color=#000000] dir [/color][color=#0000ff]in[/color][color=#000000] [/color][color=#2b91af]Enum[/color][color=#000000].GetValues([/color][color=#0000ff]typeof[/color][color=#000000]([/color][color=#2b91af]LamaDeskGame[/color][color=#000000].[/color][color=#2b91af]Dir[/color][color=#000000]))) { [/color][color=#0000ff]var[/color][color=#000000] gm = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame[/color][color=#000000](game, src, dir); [/color][color=#0000ff]if[/color][color=#000000] (gm.OK) { [/color][color=#0000ff]if[/color][color=#000000] (gm.current == trg) [/color][color=#2b91af]Console[/color][color=#000000].Write(gm); [/color][color=#0000ff]else[/color][color=#000000] TryNext(gm, gm.current, trg); } } } } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]class[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame [/color][color=#000000] { [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]LamaDeskGame[/color][color=#000000]> history; [/color][color=#0000ff]const[/color][color=#000000] [/color][color=#0000ff]int[/color][color=#000000] dimension = 8; [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]enum[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000] { None, White, Black } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]enum[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000] { N, E, S, W, NE, SE, NW, SW }; [/color][color=#2b91af]Pawn[/color][color=#000000][[/color][color=#000000],] desk; [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]bool[/color][color=#000000] OK; [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000] current; [/color][color=#2b91af]Point[/color][color=#000000] startPoint; [/color][color=#2b91af]Dir[/color][color=#000000] startDir; [/color][color=#0000ff]bool[/color][color=#000000] Dejavu([/color][color=#2b91af]LamaDeskGame[/color][color=#000000] g) { [/color][color=#0000ff]return[/color][color=#000000] g.startPoint == startPoint && g.startDir == startDir; } [/color][color=#0000ff]public[/color][color=#000000] LamaDeskGame() { desk = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000][[/color][color=#000000]dimension, dimension]; OK = [/color][color=#0000ff]true[/color][color=#000000]; history = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]List[/color][color=#000000]<[/color][color=#2b91af]LamaDeskGame[/color][color=#000000]>(); current = [/color][color=#2b91af]Point[/color][color=#000000].Empty; } [/color][color=#0000ff]public[/color][color=#000000] LamaDeskGame([/color][color=#2b91af]LamaDeskGame[/color][color=#000000] game, [/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir) : [/color][color=#0000ff]this[/color][color=#000000]() { startPoint = src; startDir = dir; [/color][color=#0000ff]foreach[/color][color=#000000] ([/color][color=#0000ff]var[/color][color=#000000] g [/color][color=#0000ff]in[/color][color=#000000] game.history) [/color][color=#0000ff]if[/color][color=#000000] (Dejavu(g)) { OK = [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]return[/color][color=#000000]; } history.AddRange(game.history); history.Add(game); [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++) [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++) desk[[/color][color=#000000]i, j] = game.desk[[/color][color=#000000]i, j]; OK = CanMove(src, dir); [/color][color=#0000ff]if[/color][color=#000000] (OK) Move(src, dir); } [/color][color=#0000ff]bool[/color][color=#000000] Target([/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir, [/color][color=#0000ff]out[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000] trg) { trg = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Point[/color][color=#000000](src.X, src.Y); [/color][color=#0000ff]switch[/color][color=#000000] (dir) { [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].N: trg.Y++; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].E: trg.X++; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].S: trg.Y--; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].W: trg.X--; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].NE: trg.Y++; trg.X++; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].NW: trg.Y++; trg.X--; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].SE: trg.Y--; trg.X++; [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Dir[/color][color=#000000].SW: trg.Y--; trg.X--; [/color][color=#0000ff]break[/color][color=#000000]; } [/color][color=#0000ff]if[/color][color=#000000] (trg.X < 0) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]if[/color][color=#000000] (trg.X >= dimension) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]if[/color][color=#000000] (trg.Y < 0) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]if[/color][color=#000000] (trg.Y >= dimension) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]true[/color][color=#000000]; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000] AtPos([/color][color=#2b91af]Point[/color][color=#000000] pt) { [/color][color=#0000ff]return[/color][color=#000000] desk[[/color][color=#000000]pt.X, pt.Y]; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] ToPos([/color][color=#2b91af]Point[/color][color=#000000] pt, [/color][color=#2b91af]Pawn[/color][color=#000000] p) { desk[[/color][color=#000000]pt.X, pt.Y] = p; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]bool[/color][color=#000000] CanMove([/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir) { [/color][color=#0000ff]if[/color][color=#000000] (AtPos(src) == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#2b91af]Point[/color][color=#000000] trg; [/color][color=#0000ff]if[/color][color=#000000] (!Target(src, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]if[/color][color=#000000] (!Target(trg, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]return[/color][color=#000000] [/color][color=#0000ff]false[/color][color=#000000]; [/color][color=#0000ff]return[/color][color=#000000] AtPos(trg) == [/color][color=#2b91af]Pawn[/color][color=#000000].None; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] Move([/color][color=#2b91af]Point[/color][color=#000000] src, [/color][color=#2b91af]Dir[/color][color=#000000] dir) { [/color][color=#0000ff]var[/color][color=#000000] pawn = AtPos(src); [/color][color=#0000ff]if[/color][color=#000000] (pawn == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000](); [/color][color=#2b91af]Point[/color][color=#000000] trg; [/color][color=#0000ff]if[/color][color=#000000] (!Target(src, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000](); [/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) == [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000](); [/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) != pawn) ToPos(trg, [/color][color=#2b91af]Pawn[/color][color=#000000].None); [/color][color=#0000ff]if[/color][color=#000000] (!Target(trg, dir, [/color][color=#0000ff]out[/color][color=#000000] trg)) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000](); [/color][color=#0000ff]if[/color][color=#000000] (AtPos(trg) != [/color][color=#2b91af]Pawn[/color][color=#000000].None) [/color][color=#0000ff]throw[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]Exception[/color][color=#000000](); ToPos(trg, pawn); ToPos(src, [/color][color=#2b91af]Pawn[/color][color=#000000].None); current = trg; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]static[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame[/color][color=#000000] TestSample() { [/color][color=#2b91af]Pawn[/color][color=#000000][[/color][color=#000000],] dsk ={ {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].Black,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].Black,[/color][color=#2b91af]Pawn[/color][color=#000000].White,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].White,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}, {[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None,[/color][color=#2b91af]Pawn[/color][color=#000000].None}}; [/color][color=#0000ff]var[/color][color=#000000] sample = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]LamaDeskGame[/color][color=#000000](); sample.desk = dsk; [/color][color=#0000ff]return[/color][color=#000000] sample; } [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]override[/color][color=#000000] [/color][color=#0000ff]string[/color][color=#000000] ToString() { [/color][color=#0000ff]var[/color][color=#000000] sb = [/color][color=#0000ff]new[/color][color=#000000] [/color][color=#2b91af]StringBuilder[/color][color=#000000](); sb.AppendFormat([/color][color=#a31515]"{0} History: {1}"[/color][color=#000000], OK ? [/color][color=#a31515]"OK"[/color][color=#000000] : [/color][color=#a31515]"ERROR"[/color][color=#000000], history.Count); sb.AppendLine(); [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] i = 0; i < dimension; i++) { [/color][color=#0000ff]for[/color][color=#000000] ([/color][color=#0000ff]int[/color][color=#000000] j = 0; j < dimension; j++) [/color][color=#0000ff]switch[/color][color=#000000] (desk[[/color][color=#000000]i, j]) { [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000].None: sb.Append([/color][color=#a31515]" "[/color][color=#000000]); [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000].White: sb.Append([/color][color=#a31515]"W "[/color][color=#000000]); [/color][color=#0000ff]break[/color][color=#000000]; [/color][color=#0000ff]case[/color][color=#000000] [/color][color=#2b91af]Pawn[/color][color=#000000].Black: sb.Append([/color][color=#a31515]"B "[/color][color=#000000]); [/color][color=#0000ff]break[/color][color=#000000]; } sb.AppendLine(); } [/color][color=#0000ff]return[/color][color=#000000] sb.ToString(); } } } [/color][/code] [size=10px]Produkt lepiče kódu[/size] Zdravim TC

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: ondro1234

8:03:26 31.10.2009

A nepotrebujes nahodou iba algoritmus, co ti najde najdlhsiu cestu? Cim dlhsia, tym viac superovych figurok vypadne a o to predsa ide, nie? Tak si skus pozriet toto: http://forum.builder.cz/read.php?13,1873867,1898975#msg-1898975 alebo zapoj uja googla. Jedine, co bude zavisiet na tebe, je urobit s daneho rozlozenia figurok vhodnu reprezentaciu pre graf. Ako napr. na ktore okolite miesta sa da skocit a na ktore nie.

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Lama

19:20:28 30.10.2009

Ahoj, ten článek o šachu je docela zajímavý,ale až moc se týká konkrétně šachů (které jsme nikdy nehrál a neznám pravidla takže z něj až tolik nepochytím).Každopádně přehodnotil jsme můj původní dotaz týkající se jednoduchého přeskoku na to,že potřebuji přeskok složený.A abych jej mohl realizovat tak potřebuji algoritmus co najde všechny cesty z jednoho místa do druhého místa.Nevíte jak se takový algoritmus jmenuje??

Děkuji vá za rady :)

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: ondra.holub

17:57:13 24.10.2009

Podíval bych se na http://www.linuxsoft.cz na seriál Šachové myšlení. Je tam dost zajímavých myšlenek a nápadů, které lze uplatnit nejenom v šachách.

Citovat příspěvek

 

Re: Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Maaartin

15:37:41 24.10.2009

> [ital]Prozatím mě napadlo v závislosti na tom jaké jsou souřadnice zdrojové figurky a cílového místa zjistit směr, kterým by se zdrojová figurka měla vydat.[/ital]

Jeden smer? Mela?

Ja bych rekl ze spis je potreba pro kazdy mozny smer zjistit jestli to jde a kam az to jde.

Pripadne pokud se skace jako v dame, tak to opakovat s tim ze preskoceny figurky se behem toho docasne odstrani.

Pro zjisteni vsech moznosti8 v danym tahu je treba projet vsecky svoje figurky a pro ne projet vsecky smery - s pripadnym dalsim skakanim atd., to bys mel jeste popsat jak to presne myslis.

Napriklad kdyz se muze skakat jen jednou a jen pres sousedy, taxi projedes pole
{(0, 1), (1, 1), (1, 0), (1, -1), ... (-1, 1)}
ten vektor v prictes ke startovni pozici, podivas se jestli je plno a kdyz jo, tak cilova pozice je start+2*v. Samozrejme kontrolujes jeste "preteceni".

Citovat příspěvek

 

Algoritmus pro zjištění koroktnosti tahu u deskové hry

Autor: Lama

13:45:03 24.10.2009

Ahoj,pustil jsme se do programování deskové hry a ctěl bych se zeptat jak naprogragramovat algoritmus pro ověření tahu.(programuji v C++)

Hrací pole je 8x8 figurky můžou jen skákat přez své i protivníkovy figurky pohyb je povolen pouze pomocí přeskoků,přeskoky mohou být vícenásobné a figurky mohou skákat v ortogonálním i diagonálním směru.

Prozatím mě napadlo v závislosti na tom jaké jsou souřadnice zdrojové figurky a cílového místa zjistit směr, kterým by se zdrojová figurka měla vydat.

Něco jako ,že když Xzf == Xcm (zf zdrojova ,cf cilove místo) tak vím ,že figurka by se měla na desce vydat nahoru nebo dolů.Jestli nahoru nebo dolů bych rozhodl na základě vyhodnocení Yzf a Ycm. Pokud Yzf > Ycm tak vím ,že figurka se má vydat směrem dolů.

Je to triviální vyhodnocení několika podmínek a proto bych se chtěl zeptat jestli je to použitelné nebo jestli víte o něčem lepším.

Děkuji vám :)

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: