Π Π°Π·ΡΠ°Π±ΠΎΡΠΊΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ ΠΈΠ³ΡΡ Π² ΡΠ°ΡΠΊΠΈ
Π Π΄Π°Π½Π½ΠΎΠΉ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ΅ ΠΎΡΠ½ΠΎΠ²Π½ΡΠΌ ΠΊΠ»Π°ΡΡΠΎΠΌ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΊΠ»Π°ΡΡ LifeWidget, ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠΈΠ²Π°ΡΡΠΈΠΉ ΡΠΎΠ²Π΅ΡΡΠ΅Π½ΠΈΠ΅ Ρ ΠΎΠ΄ΠΎΠ², ΠΊΠ°ΠΊ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°, ΡΠ°ΠΊ ΠΈ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°, ΠΈ Life Ρ ΡΠ°Π½ΡΡΠΈΠΉ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ ΠΎ ΡΠ΅ΠΊΡΡΠ΅ΠΉ ΡΠΈΡΡΠ°ΡΠΈΠΈ, Π° ΡΠ°ΠΊΠΆΠ΅ ΡΡΠ½ΠΊΡΠΈΠΈ Π²ΡΠΏΠΎΠ»Π½ΡΡΡΠΈΠ΅ Ρ ΠΎΠ΄ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° ΠΈ ΠΏΡΠΎΠ²Π΅ΡΡΡΡΠΈΠ΅ Π½Π° ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΡ Ρ ΠΎΠ΄ ΡΠ°ΡΠ΅ΠΊΠ΄Π°ΠΌΠΎΠΊ. ΠΡΠ½ΠΎΠ²Π½ΡΠΌΠΈ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ°ΠΌΠΈ, ΠΈΡΠΏΠΎΠ»Π½ΡΡΡΠΈΠΌΠΈ Π·Π°Π΄Π°ΡΠΈ ΠΊΠ»Π°ΡΡΠ° ΡΠ²Π»ΡΡΡΡΡ ai_mid (), ai_low () Π·Π΄Π΅ΡΡ ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΠ΅ΡΡΡ Π²ΡΠ±ΠΎΡ Π½Π°ΠΈΠ»ΡΡΡΠ΅Π³ΠΎ Ρ ΠΎΠ΄Π°… Π§ΠΈΡΠ°ΡΡ Π΅ΡΡ >
Π Π°Π·ΡΠ°Π±ΠΎΡΠΊΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ ΠΈΠ³ΡΡ Π² ΡΠ°ΡΠΊΠΈ (ΡΠ΅ΡΠ΅ΡΠ°Ρ, ΠΊΡΡΡΠΎΠ²Π°Ρ, Π΄ΠΈΠΏΠ»ΠΎΠΌ, ΠΊΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ)
ΠΠΈΠΆΠ΅Π³ΠΎΡΠΎΠ΄ΡΠΊΠΈΠΉ ΠΠΎΡΡΠ΄Π°ΡΡΡΠ²Π΅Π½Π½ΡΠΉ Π’Π΅Ρ Π½ΠΈΡΠ΅ΡΠΊΠΈΠΉ Π£Π½ΠΈΠ²Π΅ΡΡΠΈΡΠ΅Ρ
ΠΠ°ΡΠ΅Π΄ΡΠ° ΠΠ‘Π£
ΠΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ ΡΠ°Π±ΠΎΡΠ°
ΠΏΠΎ Π΄ΠΈΡΡΠΈΠΏΠ»ΠΈΠ½Π΅: «Π’Π΅Ρ Π½ΠΎΠ»ΠΎΠ³ΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ»
ΠΠΎΠ²Π³ΠΎΡΠΎΠ΄
ΠΠ°Π½Π½Π°Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ° ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΠ΅Ρ ΠΈΠ³ΡΡ ΠΏΠΎ 2-ΠΌ ΡΡΠΎΠ²Π½ΡΠΌ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ, Π΄Π»Ρ ΠΈΠ³ΡΡ ΠΏΠΎΠ»Π΅ΠΉ. ΠΡΠ΅Π΄ΡΡΠΌΠ°ΡΡΠΈΠ²Π°Π΅ΡΡΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΠΎΡΠΊΠ°ΡΠ° Π½Π°Π·Π°Π΄ Π½Π° Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ Ρ ΠΎΠ΄ΠΎΠ². ΠΠΎΠΈΡΠΊ Ρ ΠΎΠ΄Π° ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΠ΅ΡΡΡ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠΎΠΌ Ρ ΠΏΠΎΠΌΠΎΡΡΡ Π±-Π² ΠΏΡΠΎΡΠ΅Π΄ΡΡΡ.
ΠΡΠ°Π²ΠΈΠ»Π° ΠΈΠ³ΡΡ
ΠΡΠ°Π²ΠΈΠ»Π° ΠΈΠ³ΡΡ Π² ΡΠ°ΡΠΊΠΈ Π΄ΠΎΡΡΠ°ΡΠΎΡΠ½ΠΎ ΠΏΡΠΎΡΡΡ ΠΈ ΠΏΠΎΠ½ΡΡΠ½Ρ. Π‘ΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ ΠΊΠ»Π΅ΡΡΠ°ΡΠ°Ρ Π΄ΠΎΡΠΊΠ°, ΠΏΠΎΡ ΠΎΠΆΠ°Ρ Π½Π° ΡΠ°Ρ ΠΌΠ°ΡΠ½ΡΡ, Ρ Π±Π΅Π»ΡΠΌΠΈ (ΡΠ²Π΅ΡΠ»ΡΠΌΠΈ) ΠΈ ΡΡΡΠ½ΡΠΌΠΈ (ΡΡΠΌΠ½ΡΠΌΠΈ) ΠΊΠ»Π΅ΡΠΊΠ°ΠΌΠΈ. Π¨Π°ΡΠΊΠΈ ΠΎΠ±ΠΎΠΈΡ ΡΠΎΠΏΠ΅ΡΠ½ΠΈΠΊΠΎΠ² ΡΠ°ΡΠΏΠΎΠ»Π°Π³Π°ΡΡΡΡ Π² Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΡΠ΄ΠΎΠ², Π½Π°ΡΠΈΠ½Π°Ρ ΠΎΡ ΠΊΡΠ°Ρ Π΄ΠΎΡΠΊΠΈ, Π½Π° ΡΡΠΌΠ½ΡΡ ΠΊΠ»Π΅ΡΠΊΠ°Ρ . ΠΠ΅ΡΠ²ΡΠΌΠΈ Ρ ΠΎΠ΄ΡΡ Π±Π΅Π»ΡΠ΅. Π¨Π°ΡΠΊΠΈ Ρ ΠΎΠ΄ΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΠΎ Π΄ΠΈΠ°Π³ΠΎΠ½Π°Π»ΠΈ ΠΈ, ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²Π΅Π½Π½ΠΎ ΠΌΠΎΠ³ΡΡ ΠΏΠ΅ΡΠ΅Π΄Π²ΠΈΠ³Π°ΡΡΡΡ ΡΠΎΠ»ΡΠΊΠΎ ΠΏΠΎ ΡΡΡΠ½ΡΠΌ ΠΊΠ²Π°Π΄ΡΠ°ΡΠ°ΠΌ Π΄ΠΎΡΠΊΠΈ. Π₯ΠΎΠ΄ΠΈΡΡ ΠΎΠ±ΡΡΠ½ΡΠ΅ ΡΠ°ΡΠΊΠΈ ΠΌΠΎΠ³ΡΡ ΡΠΎΠ»ΡΠΊΠΎ Π²ΠΏΠ΅ΡΡΠ΄. ΠΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ Π·Π΄Π΅ΡΡ ΡΠΎΡΡΠ°Π²Π»ΡΡΡ Π»ΠΈΡΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ Π±ΠΈΡΡ ΡΠ°ΡΠΊΠΈ ΠΏΡΠΎΡΠΈΠ²Π½ΠΈΠΊΠ° Π½Π°Π·Π°Π΄ Π² Π½Π΅ΠΊΠΎΡΠΎΡΡΡ ΡΠ°Π·Π½ΠΎΠ²ΠΈΠ΄Π½ΠΎΡΡΡΡ ΠΏΡΠ°Π²ΠΈΠ» ΠΈΠ³ΡΡ. ΠΠΈΡΡ ΡΠ°ΡΠΊΡ ΡΠΎΠΏΠ΅ΡΠ½ΠΈΠΊΠ° ΠΎΠ·Π½Π°ΡΠ°Π΅Ρ «ΠΏΠ΅ΡΠ΅ΠΏΡΡΠ³Π½ΡΡΡ» ΡΠ΅ΡΠ΅Π· Π½Π΅Ρ ΠΏΠΎ Π΄ΠΈΠ°Π³ΠΎΠ½Π°Π»ΠΈ. Π ΡΡΠΎΠΌ ΡΠ»ΡΡΠ°Π΅ Π±ΠΈΠ²ΡΠ°Ρ ΡΠ°ΡΠΊΠ° ΡΡΠ°Π½ΠΎΠ²ΠΈΡΡΡ Π·Π° Π±ΠΈΡΠΎΠΉ, ΠΊΠΎΡΠΎΡΠ°Ρ Π² ΡΠ²ΠΎΡ ΠΎΡΠ΅ΡΠ΅Π΄Ρ ΡΠ½ΠΈΠΌΠ°Π΅ΡΡΡ Ρ Π΄ΠΎΡΠΊΠΈ. Π¨Π°ΡΠΊΠ°, Π΄ΠΎΡΡΠΈΠ³ΡΠ°Ρ ΠΏΡΠΎΡΠΈΠ²ΠΎΠΏΠΎΠ»ΠΎΠΆΠ½ΠΎΠ³ΠΎ ΠΊΡΠ°Ρ Π΄ΠΎΡΠΊΠΈ, ΠΏΡΠ΅Π²ΡΠ°ΡΠ°Π΅ΡΡΡ Π² Π΄Π°ΠΌΠΊΡ. ΠΠ°ΠΌΠΊΠ° ΠΌΠΎΠΆΠ΅Ρ ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ°ΡΡΡΡ ΠΊΠ°ΠΊ Π²ΠΏΠ΅ΡΡΠ΄, ΡΠ°ΠΊ ΠΈ Π½Π°Π·Π°Π΄. Π¦Π΅Π»Ρ ΠΈΠ³ΡΡ — Π·Π°Π±Π»ΠΎΠΊΠΈΡΠΎΠ²Π°ΡΡ ΠΈΠ»ΠΈ ΡΠ±ΡΠ°ΡΡ Ρ Π΄ΠΎΡΠΊΠΈ Π²ΡΠ΅ ΡΠ°ΡΠΊΠΈ ΠΏΡΠΎΡΠΈΠ²Π½ΠΈΠΊΠ°.
ΠΠ΅ΡΠΌΠΎΡΡΡ Π½Π° ΠΏΡΠΎΡΡΠΎΡΡ ΠΏΡΠ°Π²ΠΈΠ», ΡΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ ΠΌΠ°ΡΡΠ° ΡΠ°Π·Π½ΠΎΠ²ΠΈΠ΄Π½ΠΎΡΡΠ΅ΠΉ ΡΡΠΎΠΉ ΠΈΠ³ΡΡ Π² ΠΌΠΈΡΠ΅. ΠΡΠ΅ ΡΡ ΠΎΠΆΠΈΠ΅ ΠΏΡΠ°Π²ΠΈΠ»Π° ΡΠ°ΡΠ΅ΠΊ ΡΠΊΠ°Π·Π°Π½Ρ Π²ΡΡΠ΅. ΠΠ°Π»Π΅Π΅ Π½Π°ΡΠΈΠ½Π°ΡΡΡΡ Ρ ΠΎΡΡ ΠΈ ΠΌΠ΅ΡΡΠ°ΠΌΠΈ Π½Π΅Π·Π½Π°ΡΠΈΡΠ΅Π»ΡΠ½ΡΠ΅, Π½ΠΎ ΡΠ°Π·Π»ΠΈΡΠΈΡ.
ΠΠΎΠ΄Π΄Π°Π²ΠΊΠΈ. Π¨Π°ΡΠΊΠΈ Π² ΠΏΡΠΈΠ²ΡΡΠ½ΠΎΠΌ Π΄Π»Ρ Π½Π°Ρ ΠΏΠΎΠ½ΠΈΠΌΠ°Π½ΠΈΠΈ.
Β· ΠΠΎΡΠΊΠ°: 8×8 (ΠΊΠ°ΠΊ Π² ΡΠ°Ρ ΠΌΠ°ΡΠ°Ρ );
Β· ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΠ°ΡΠ΅ΠΊ Ρ ΠΈΠ³ΡΠΎΠΊΠ°: 12;
Β· Π Π°ΡΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅: ΠΏΠ΅ΡΠ²ΡΠ΅ 3 ΡΡΠ΄Π°;
Β· ΠΠΈΡΡ: ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ»ΡΠ½ΠΎΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΠ°ΡΠ΅ΠΊ Π² Π»ΡΠ±ΠΎΠΌ Π½Π°ΠΏΡΠ°Π²Π»Π΅Π½ΠΈΠΈ;
Β· ΠΠΈΡΡ Π½Π°Π·Π°Π΄: ΡΠ°Π·ΡΠ΅ΡΠ΅Π½ΠΎ;
Β· ΠΠ°ΠΌΠΊΠ°: ΠΏΠ΅ΡΠ΅Π΄Π²ΠΈΠ³Π°Π΅ΡΡΡ Π½Π° Π»ΡΠ±ΠΎΠ΅ ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΏΠΎΠ»Π΅ΠΉ; Π΅ΡΠ»ΠΈ ΡΠ°ΡΠΊΠ° Π±ΠΈΠ»Π° ΡΠ΅ΡΠ΅Π· ΠΏΠΎΠ»Π΅ ΠΏΡΠ΅Π²ΡΠ°ΡΠ΅Π½ΠΈΡ, ΠΎΠ½Π° Π²ΡΡ ΡΠ°Π²Π½ΠΎ ΡΡΠ°Π½ΠΎΠ²ΠΈΡΡΡ Π΄Π°ΠΌΠΊΠΎΠΉ;
ΠΡΠ°Π²ΠΈΠ»Π° ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡ ΡΡΡΡΠΊΠΈΠΌ ΡΠ°ΡΠΊΠ°ΠΌ. ΠΠΈΡΡ ΡΠ°ΡΠΊΠΈ ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎ. Π¦Π΅Π»Ρ ΠΈΠ³ΡΡ — ΠΊΠ°ΠΊ ΠΌΠΎΠΆΠ½ΠΎ Π±ΡΡΡΡΠ΅Π΅ ΡΠ½ΡΡΡ Ρ Π΄ΠΎΡΠΊΠΈ Π²ΡΠ΅ ΡΠ²ΠΎΠΈ ΡΠ°ΡΠΊΠΈ. ΠΡΠΈΠ³ΡΡΠ²Π°Π΅Ρ ΡΠΎΡ, ΠΊΡΠΎ ΠΏΠ΅ΡΠ²ΡΠΌ ΠΎΡΡΠ°Π»ΡΡ Π±Π΅Π· ΡΠΈΠ³ΡΡ.
ΠΠ½ΡΡΡΡΠΊΡΠΈΡ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ
ΠΠ»Ρ Π½Π°ΡΠ°Π»Π° ΠΈΠ³ΡΡ Π½Π΅ΠΎΠ±Ρ ΠΎΠ΄ΠΈΠΌΠΎ Π²ΡΠ±ΡΠ°ΡΡ ΠΏΡΠ½ΠΊΡ Filelevel_(Π²ΡΠ±ΡΠ°ΡΡ ΡΡΠΎΠ²Π΅Π½Ρ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ), Π·Π°ΡΠ΅ΠΌ Π½Π°ΡΠ°ΡΡ ΠΈΠ³ΡΠ°ΡΡ ΠΠΎΡΠ»Π΅ Π²ΡΠ±ΠΎΡΠ° ΡΡΠΎΠ²Π½Ρ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ ΠΌΠΎΠΆΠ½ΠΎ Π½Π°ΡΠΈΠ½Π°ΡΡ ΠΈΠ³ΡΠ°ΡΡ, ΠΎΡΠΊΡΡΠ²Π°Π΅ΡΡΡ ΠΈΠ³ΡΠΎΠ²ΠΎΠ΅ ΠΏΠΎΠ»Π΅. Π©Π΅Π»ΠΊΠ°Ρ ΠΌΡΡΡΡ Π½Π° ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΡ ΡΡΠ΅ΠΉΠΊΠ°Ρ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ ΡΠΎΠ²Π΅ΡΡΠ°Π΅Ρ Ρ ΠΎΠ΄, ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ°Ρ ΡΠ°ΡΠΊΠΈ Π² ΡΠΊΠ°Π·Π°Π½Π½ΠΎΠ΅ ΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅. ΠΠ³ΡΠ° Π²Π΅Π΄Π΅ΡΡΡ Ρ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠΎΠΌ, ΠΏΠΎΡΡΠΎΠΌΡ ΠΏΠΎΡΠ»Π΅ Π²Π°ΡΠ΅Π³ΠΎ Ρ ΠΎΠ΄Π° ΠΎΠΆΠΈΠ΄Π°ΠΉΡΠ΅ Ρ ΠΎΠ΄Π° ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°. ΠΡΡΡ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΠΎΡΠΊΠ°ΡΠ° ΠΈΠ³ΡΡ Π½Π° Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ Ρ ΠΎΠ΄ΠΎΠ² Π½Π°Π·Π°Π΄ (CTRL+S, CTRL+N).
ΠΠ½ΡΡΡΡΠΊΡΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΡΠ°
Π Π΄Π°Π½Π½ΠΎΠΉ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ΅ ΠΎΡΠ½ΠΎΠ²Π½ΡΠΌ ΠΊΠ»Π°ΡΡΠΎΠΌ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΊΠ»Π°ΡΡ LifeWidget, ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠΈΠ²Π°ΡΡΠΈΠΉ ΡΠΎΠ²Π΅ΡΡΠ΅Π½ΠΈΠ΅ Ρ ΠΎΠ΄ΠΎΠ², ΠΊΠ°ΠΊ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°, ΡΠ°ΠΊ ΠΈ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°, ΠΈ Life Ρ ΡΠ°Π½ΡΡΠΈΠΉ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ ΠΎ ΡΠ΅ΠΊΡΡΠ΅ΠΉ ΡΠΈΡΡΠ°ΡΠΈΠΈ, Π° ΡΠ°ΠΊΠΆΠ΅ ΡΡΠ½ΠΊΡΠΈΠΈ Π²ΡΠΏΠΎΠ»Π½ΡΡΡΠΈΠ΅ Ρ ΠΎΠ΄ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° ΠΈ ΠΏΡΠΎΠ²Π΅ΡΡΡΡΠΈΠ΅ Π½Π° ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΡ Ρ ΠΎΠ΄ ΡΠ°ΡΠ΅ΠΊΠ΄Π°ΠΌΠΎΠΊ. ΠΡΠ½ΠΎΠ²Π½ΡΠΌΠΈ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ°ΠΌΠΈ, ΠΈΡΠΏΠΎΠ»Π½ΡΡΡΠΈΠΌΠΈ Π·Π°Π΄Π°ΡΠΈ ΠΊΠ»Π°ΡΡΠ° ΡΠ²Π»ΡΡΡΡΡ ai_mid (), ai_low () Π·Π΄Π΅ΡΡ ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΠ΅ΡΡΡ Π²ΡΠ±ΠΎΡ Π½Π°ΠΈΠ»ΡΡΡΠ΅Π³ΠΎ Ρ ΠΎΠ΄Π° ΠΈ ΠΏΠ΅ΡΠ΅Ρ ΠΎΠ΄ ΠΊ ΡΠ»Π΅Π΄ΡΡΡΠ΅ΠΉ ΠΈΠ³ΡΠΎΠ²ΠΎΠΉ ΡΠΈΡΡΠ°ΡΠΈΠΈ, mousePressEvent () Π²ΡΠΏΠΎΠ»Π½ΡΠ΅Ρ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΡ Π½Π°ΠΆΠ°ΡΠΈΠΉ ΠΌΡΡΠΈ ΠΈ Ρ ΠΎΠ΄ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°, paintEvent () ΡΠΈΡΡΠ΅ΡΠΏΠ΅ΡΠ΅ΡΠΈΡΠΎΠ²ΡΠ²Π°Π΅Ρ ΠΈΠ³ΡΠΎΠ²ΡΡ Π΄ΠΎΡΠΊΡ ΠΏΠΎΡΠ»Π΅ Ρ ΠΎΠ΄Π° ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°, ΡΠ°ΠΊΠΆΠ΅ Π·Π΄Π΅ΡΡ Ρ ΡΠ°Π½ΠΈΡΡΡ ΠΈΡΡΠΎΡΠΈΡ Ρ ΠΎΠ΄ΠΎΠ², ΠΊΠΎΡΠΎΡΠ°Ρ ΠΏΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ ΠΎΡΠΊΠ°ΡΠΈΡΡ ΠΈΠ³ΡΡ Π½Π°Π·Π°Π΄. ΠΡΡΠΎΡΠΈΡΡΠΊΠ°Π·Π°ΡΠ΅Π»ΠΈ Π½Π° ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ Ρ ΠΎΠ΄Ρ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ° Ρ ΡΠ°Π½ΡΡΡΡ Π² ΡΠΎΠ±ΡΡΠ²Π΅Π½Π½ΠΎΠΌ ΠΊΠ»Π°ΡΡΠ΅ Vector, ΠΊΠΎΡΠΎΡΡΠΉ Π²ΠΊΠ»ΡΡΠ°Π΅Ρ Π² ΡΠ΅Π±Ρ ΡΠ΄ΠΎΠ±Π½ΠΎΠ΅ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ Ρ ΠΎΠ΄Π½ΠΎΠΌΠ΅ΡΠ½ΡΠΌ ΠΌΠ°ΡΡΠΈΠ²ΠΎΠΌ.
ΠΠ»Π°ΡΡ Life ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ Π² ΡΠ΅Π±Π΅, Π²ΠΎ-ΠΏΠ΅ΡΠ²ΡΡ , Π΄Π²ΡΠΌΠ΅ΡΠ½ΡΠΉ ΠΌΠ°ΡΡΠΈΠ² ΠΎΠ±ΡΠ΅ΠΊΡΠΎΠ² ΠΊΠ»Π°ΡΡ Point (ΠΊΠΎΡΠΎΡΡΠΉ Ρ ΡΠ°Π½ΠΈΡ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ ΠΎ ΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ ΡΠ°ΡΠΊΠΈ ΠΈ Π΅Ρ ΡΠΈΠΏΠ΅) Ρ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΠ΅ΠΉ ΠΎ ΡΠ°ΡΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ Π½Π° ΠΏΠΎΠ»Π΅ ΡΠ°ΡΠ΅ΠΊ, ΡΠ°ΠΊΠΆΠ΅ bool ΠΌΠ°ΡΡΠΈΠ² cells, Ρ ΡΠ°Π½ΡΡΠΈΠΉ ΠΈΠ½ΡΠΎΡΠΌΠ°ΡΠΈΡ ΠΎ Π½Π°ΠΆΠ°ΡΠΈΡΡ ΠΌΡΡΠΈ.
ΠΡΠ½ΠΎΠ²Π½ΡΠΌ ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΊΠ»Π°ΡΡ ai_Trees, Π² Π½ΡΠΌ ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΡΡΡΡ Π°Π»Π³ΠΎΡΠΈΡΠΌΠ° ΠΏΠΎΠ΄ΡΡΠ΅ΡΠ° Ρ ΠΎΠ΄ΠΎΠ², ΠΎΡΠ΅Π½ΠΊΠ° Ρ ΠΎΠ΄ΠΎΠ² ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°, ΠΏΠΎΡΡΡΠΎΠ΅Π½ΠΈΠ΅ Π΄Π΅ΡΠ΅Π²Π° ΠΏΠΎΠΈΡΠΊΠ° Π»ΡΡΡΠ΅Π³ΠΎ Ρ ΠΎΠ΄Π° ΠΈΡΡ ΠΎΠ΄Ρ ΠΈΠ· ΠΎΡΠ΅Π½ΠΊΠΈ ΡΡΠ½ΠΊΡΠΈΠΉ.
ΠΠ»Π°ΡΡ MainWindow ΡΡΠΎ ΠΊΠ»Π°ΡΡ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ° ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ, ΠΌΠ΅Π½ΡΠΏΠ°Π½Π΅Π»Ρ ΠΊΠ½ΠΎΠΏΠΎΠΊ ΠΎΡΠΊΠ°ΡΠ° ΠΈΠ³ΡΡΡΡΠ°ΡΡΡ ΡΡΡΠΎΠΊΠ°Π²ΡΠ²ΠΎΠ΄ ΡΠ΅Π½ΡΡΠ°Π»ΡΠ½ΠΎΠ³ΠΎ Π²ΠΈΠ΄ΠΆΠ΅ΡΠ° ΠΈΠ³ΡΡ (ΠΈΠ³ΡΠΎΠ²ΠΎΠΉ Π΄ΠΎΡΠΊΠΈ), ΡΠ°ΠΊΠΆΠ΅ Π² ΡΡΠΎΠΌ ΠΊΠ»Π°ΡΡΠ΅ ΠΎΡΡΡΠ΅ΡΡΠ²Π»ΡΠ΅ΡΡΡ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ° Π½Π°ΠΆΠ°ΡΠΈΠΉΠ²ΡΠ±ΠΎΡΠ° ΠΏΡΠ½ΠΊΡΠΎΠ² ΠΌΠ΅Π½Ρ. ΠΡΠΎΠΌΠ΅ ΡΠΎΠ³ΠΎ, Π² ΠΊΠ»Π°ΡΡΠ΅ Field ΡΠΎΠ΄Π΅ΡΠΆΠΈΡΡΡ ΡΠΏΠΈΡΠΎΠΊ ΡΠ²ΠΎΠ±ΠΎΠ΄Π½ΡΡ ΡΡΠ΅Π΅ΠΊ Π΄Π»Ρ Π·Π°Π΄Π°Ρ ΠΊΠ»Π°ΡΡΠ° ΠΈ, Π² ΠΏΠ΅ΡΠ²ΡΡ ΠΎΡΠ΅ΡΠ΅Π΄Ρ, Π΄Π»Ρ Π³Π΅Π½Π΅ΡΠ°ΡΠΎΡΠΎΠ² Ρ ΠΎΠ΄Π°.
ΠΠ΅ΡΡ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ΠΌ Qt-ΡΡΠΎ ΠΊΡΠΎΡΡ-ΠΏΠ»Π°ΡΡΠΎΡΠΌΠ΅Π½Π½ΡΠΉ ΠΈΠ½ΡΡΡΡΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠΈ ΠΠ Π½Π° ΡΠ·ΡΠΊΠ΅ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ C++. ΠΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ Π·Π°ΠΏΡΡΠΊΠ°ΡΡ Π½Π°ΠΏΠΈΡΠ°Π½Π½ΠΎΠ΅ Ρ Π΅Π³ΠΎ ΠΏΠΎΠΌΠΎΡΡΡ ΠΠ Π² Π±ΠΎΠ»ΡΡΠΈΠ½ΡΡΠ²Π΅ ΡΠΎΠ²ΡΠ΅ΠΌΠ΅Π½Π½ΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΎΠ½Π½ΡΡ ΡΠΈΡΡΠ΅ΠΌ ΠΏΡΡΡΠΌ ΠΏΡΠΎΡΡΠΎΠΉ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡΠΈΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ Π΄Π»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΠ‘ Π±Π΅Π· ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ ΠΈΡΡ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΊΠΎΠ΄Π°. ΠΠΊΠ»ΡΡΠ°Π΅Ρ Π² ΡΠ΅Π±Ρ Π²ΡΠ΅ ΠΎΡΠ½ΠΎΠ²Π½ΡΠ΅ ΠΊΠ»Π°ΡΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ ΠΌΠΎΠ³ΡΡ ΠΏΠΎΡΡΠ΅Π±ΠΎΠ²Π°ΡΡΡΡ ΠΏΡΠΈ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠ΅ ΠΏΡΠΈΠΊΠ»Π°Π΄Π½ΠΎΠ³ΠΎ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠ½ΠΎΠ³ΠΎ ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠ΅Π½ΠΈΡ, Π½Π°ΡΠΈΠ½Π°Ρ ΠΎΡ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² Π³ΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΎΠ³ΠΎ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠ° ΠΈ Π·Π°ΠΊΠ°Π½ΡΠΈΠ²Π°Ρ ΠΊΠ»Π°ΡΡΠ°ΠΌΠΈ Π΄Π»Ρ ΡΠ°Π±ΠΎΡΡ Ρ ΡΠ΅ΡΡΡ, Π±Π°Π·Π°ΠΌΠΈ Π΄Π°Π½Π½ΡΡ ΠΈ XML. Qt ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΏΠΎΠ»Π½ΠΎΡΡΡΡ ΠΎΠ±ΡΠ΅ΠΊΡΠ½ΠΎ-ΠΎΡΠΈΠ΅Π½ΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠΌ, Π»Π΅Π³ΠΊΠΎ ΡΠ°ΡΡΠΈΡΡΠ΅ΠΌΡΠΌ ΠΈ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°ΡΡΠΈΠΌ ΡΠ΅Ρ Π½ΠΈΠΊΡ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½ΡΠ½ΠΎΠ³ΠΎ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ.
ΠΡΠΎΠ³ΡΠ°ΠΌΠΌΠ°
ΠΈΠ³ΡΠ° ΡΠ°ΡΠΊΠΈ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΡ Π°Π»Π³ΠΎΡΠΈΡΠΌ
Ai_tree.h
#ifndef AI_TREE_H
#define AI_TREE_H
#include «point.h»
#include «Vector.h»
using namespace std;
class Tree
{
public:
~Tree ();
size_t move_x;//ΡΠ΅ΠΊΡΡΠ°Ρ Π₯
size_t move_y;//ΡΠ΅ΠΊΡΡΠ°Ρ Π£
size_t move_new_x;//Π½ΠΎΠ²Π°Ρ Π₯
size_t move_new_y;//Π½ΠΎΠ²Π°Ρ Π£
int rang;// Π½Π°ΡΠΊΠΎΠ»ΡΠΊΠΎ ΡΠ΄Π°ΡΠ½ΡΠΉ Ρ ΠΎΠ΄ Π΄Π»Ρ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°
point** points;// ΠΈΠ³ΡΠΎΠ²ΠΎΠ΅ ΠΏΠΎΠ»Π΅
Vector ai_Trees;// ΡΠΊΠ°Π·Π°ΡΠ΅Π»ΠΈ Π½Π° ΡΠ»Π΅Π΄ΡΡΡΠΈΠ΅ ΠΈΠ³ΡΠΎΠ²ΡΠ΅ ΡΠΈΡΡΠ°ΡΠΈΠΈ
int ai_move_rating (point**, size_t, size_t); // ΠΎΡΠ΅Π½ΠΊΠ° Ρ ΠΎΠ΄Π° ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°
int human_move_rating (point** points, size_t i, size_t j);// ΠΎΡΠ΅Π½ΠΊΠ° Ρ ΠΎΠ΄Π° ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°
point** ai_copy_swap (point**, size_t, size_t, size_t, size_t); // ΠΎΠΏΡΠ΅Π΄Π΅Π»Π΅Π½ΠΈΠ΅ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΡΡ Ρ ΠΎΠ΄ΠΎΠ² ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°
Tree* first (point** points);// ΠΏΠ΅ΡΠ²ΡΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ Π΄Π΅ΡΠ΅Π²Π°
Tree* insert_low (Tree*, point**);// Π½ΠΎΠ²ΡΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ Π΄Π΅ΡΠ΅Π²Π°
Tree* insert_mid (Tree*, point**);// Π½ΠΎΠ²ΡΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ Π΄Π΅ΡΠ΅Π²Π°
void print (Tree*, size_t);// Π²ΡΠ²ΠΎΠ΄ ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ Π΄Π΅ΡΠ΅Π²Π°
void change_board (point** board, point** new_board);// ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ ΠΈΠ³ΡΠΎΠ²ΠΎΠ³ΠΎ ΠΏΠΎΠ»Ρ
size_t num_moves (point**); //ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Ρ ΠΎΠ΄ΠΎΠ² ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°
size_t num_moves_human (point** board);//ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Ρ ΠΎΠ΄ΠΎΠ² ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°
bool frag_comp_bool (point** points, size_t x, size_t y);//ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° Π½Π° ΡΡΠ΅Π΄Π°Π½ΠΈΠ΅ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠΎΠΌ
bool frag_king_ai (point** points, size_t x, size_t y);//ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° Π½Π° ΡΡΠ΅Π΄Π°Π½ΠΈΠ΅ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠΎΠΌ Π΄Π°ΠΌΠΊΠΎΠΉ
};
#endif
Life.h
#ifndef LIFE_H
#define LIFE_H
#include «point.h»
#include
class Life: public QObject
{
Q_OBJECT
public:
Life (QObject *parent = 0);
virtual ~Life ();
void setGridSize (const QSize &size);// ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΏΠΎΠ»Ρ
QSize gridSize () const;// Π²ΠΎΠ·Π²ΡΠ°ΡΠ΅Π½ΠΈΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΡ ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΏΠΎΠ»Ρ
void setCell (const QPoint &pos, bool value);// ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΏΠΎΠ»Ρ
bool cell (const QPoint &pos) const;// Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ Π°ΠΊΡΠΈΠ²Π½ΠΎΡΡΡ ΠΊΠ»Π΅ΡΠΊΠΈ
bool Cell_King (size_t x, size_t y);// ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° Π½Π° Π΄Π°ΠΌΠΊΡ
bool move (size_t x, size_t y, size_t new_x, size_t new_y);// Ρ ΠΎΠ΄ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊΠ°
bool frag (size_t x, size_t y, size_t new_x, size_t new_y);// Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡΡ ΠΏΠΎΠ΅Π΄Π°Π½ΠΈΡ
bool frag_comp (size_t x, size_t y);// Ρ ΠΎΠ΄ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°
bool frag_move (size_t x, size_t y, size_t new_x, size_t new_y);// ΠΏΠΎΠ΅Π΄Π°Π½ΠΈΠ΅ ΡΠ΅Π»ΠΎΠ²Π΅ΠΊ
bool frag_king (size_t x, size_t y);// ΠΏΠΎΠ΅Π΄Π°Π½ΠΈΠ΅ Π΄Π°ΠΌΠΊΠΎΠΉ
bool move_ai_king (size_t x, size_t y);// ΠΏΠΎΠ΅Π΄Π°Π½ΠΈΠ΅ Π΄Π°ΠΌΠΊΠΎΠΉ ΠΊΠΎΠΌΠΏΡΡΡΠ΅ΡΠ°
void refresh ();// ΡΠ±ΡΠΎΡ Π΄Π°Π½Π½ΡΡ ΠΏΠΎΠ»Ρ
void deleteCells ();// ΡΠ΄Π°Π»Π΅Π½ΠΈΠ΅ Π΄Π°Π½Π½ΡΡ ΠΏΠΎΠ»Ρ
void new_game ();// Π½Π°ΡΠ°Π»ΠΎ Π½ΠΎΠ²ΠΎΠΉ ΠΈΠ³ΡΡ
bool game_over ();// ΠΏΡΠΎΠ²Π΅ΡΠΊΠ° ΠΊΠΎΠ½ΡΠ° ΠΈΠ³ΡΡ
point **points; // ΠΏΠΎΠ»Π΅
bool **cells;// Π½Π°ΠΆΠ°ΡΠΈΡ
point tmp;
private:
size_t red_count;// ΠΊΠΎΠ»-Π²ΠΎ ΠΊΡΠ°ΡΠ½ΡΡ
size_t blue_count;// ΠΊΠΎΠ»-Π²ΠΎ ΡΠΈΠ½ΠΈΡ
QSize gridSizeProperty;// ΡΠ°Π·ΠΌΠ΅Ρ ΠΏΠΎΠ»Ρ
};
#endif // LIFE_H
LifeWidget.h
#ifndef LIFEWIDGET_H
#define LIFEWIDGET_H
#include
#include «life.h»
#include «ai_tree.h»
#include «Vector.h»
#include «Vector.cpp»
#include «vector»
class LifeWidget: public QWidget
{
Q_OBJECT
public:
LifeWidget (QWidget *parent = 0);
virtual ~LifeWidget ();
void setGridSize (const QSize &size);// ΡΡΡΠ°Π½ΠΎΠ²ΠΊΠ° ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΏΠΎΠ»Ρ
QSize gridSize () const;//Π²ΠΎΠ·Π²ΡΠ°Ρ ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΏΠΎΠ»Ρ
void setCellSize (int size);//ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΊΠ»Π΅ΡΠΊΠΈ
int cellSize () const;//Π²ΠΎΠ·Π²ΡΠ°Ρ ΡΠ°Π·ΠΌΠ΅ΡΠ° ΠΊΠ»Π΅ΡΠΊΠΈ
void Draw_Cell (QPainter *painter, QBrush PenBrush, int pen_size,
QBrush RectBrush, int x0, int y0, int size);//ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΊΠ»Π΅ΡΠΊΠΈ
void Draw_Ellipse (QPainter *painter, QBrush PenBrush, int pen_size,
QBrush RectBrush, int x0, int y0, int size);//ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΡΠ°ΡΠΊΠΈ
void ai_low ();//Π½ΠΈΠ·ΠΊΠΈΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ
void ai_mid ();//ΡΡΠ΅Π΄Π½ΠΈΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ
void set_game_level (size_t level);//ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΡΠ΅ΠΆΠΈΠΌΠ° ΠΈΠ³ΡΡ
size_t cout_moves;//ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ Ρ ΠΎΠ΄ΠΎΠ²
Life *life;
size_t player;//ΡΠ΅ΠΊΡΡΠΈΠΉ ΠΈΠ³ΡΠΎΠΊ
Tree *game;//Π΄Π΅ΡΠ΅Π²ΠΎ Ρ ΠΎΠ΄ΠΎΠ²
point **p;//Π±ΡΡΠ΅Ρ ΠΈΡΡΠΎΡΠΈΠΈ Ρ ΠΎΠ΄ΠΎΠ²
vector history_moves;//ΠΈΡΡΠΎΡΠΈΡ Ρ ΠΎΠ΄ΠΎΠ²
void add_event_history (point**);//Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ Π² ΠΈΡΡΠΎΡΠΈΡ
void history_up ();//Ρ ΠΎΠ΄ Π²ΠΏΠ΅ΡΡΠ΄
void history_down ();//Ρ ΠΎΠ΄ Π½Π°Π·Π°Π΄
int state_now;//ΡΠ΅ΠΊΡΡΠ΅Π΅ ΠΏΠΎΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ ΠΈΡΡΠΎΡΠΈΠΈ
protected:
QSize minimumSizeHint () const;
QSize sizeHint () const;
void mousePressEvent (QMouseEvent *event);//ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠ° Π½Π°ΠΆΠ°ΡΠΈΠΉ ΠΌΡΡΠΈ
void paintEvent (QPaintEvent *event);//ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΈ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅ Π΄ΠΎΡΠΊΠΈ
private:
size_t game_level;//ΡΠ΅ΠΊΡΡΠΈΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΡΠ»ΠΎΠΆΠ½ΠΎΡΡΠΈ
bool click1;
bool click2;
int cellSizeProperty;
};
#endif // LIFEWIDGET_H
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include «lifewidget.h»
QT_BEGIN_NAMESPACE
class QAction;
class QListWidget;
class QMenu;
class QTextEdit;
QT_END_NAMESPACE
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow ();
private slots:
void newLetter ();
void save ();
void about ();
void level_mid ();
void level_low ();
private:
void createActions ();
void createMenus ();
void createToolBars ();
void createStatusBar ();
LifeWidget *life;
QMenu *fileMenu;
QMenu *helpMenu;
QToolBar *fileToolBar;
QToolBar *editToolBar;
QAction *newLetterAct;
QAction *saveAct;
QAction *low;
QAction *mid;
QAction *aboutAct;
QAction *aboutQtAct;
QAction *quitAct;
};
#endif
Point.h
#ifndef POINT_H
#define POINT_H
enum checker
{
RED = 1,// ΠΊΡΠ°ΡΠ½Π°Ρ ΡΠ°ΡΠΊΠ°
BLUE= 2,// ΡΠΈΠ½ΡΡ ΡΠ°ΡΠΊΠ°
REDKING = 3,// ΠΊΡΠ°ΡΠ½Π°Ρ Π΄Π°ΠΌΠΊΠ°
BLUEKING = 4, // ΡΠΈΠ½ΡΡ Π΄Π°ΠΌΠΊΠ°
WHITECELL = 0,// Π½Π΅Ρ ΠΎΠ΄ΠΎΠ²Π°Ρ ΠΊΠ»Π΅ΡΠΊΠ°
EMPTYCELL = 9,// Ρ ΠΎΠ΄ΠΎΠ²Π°Ρ, ΠΏΡΡΡΠ°Ρ ΠΊΠ»Π΅ΡΠΊΠ°
};
class point
{
int x;//Π£
int y;//Π₯
int type;//ΡΠΈΠΏ
public:
int getX (){return x;}
int getY (){return y;}
int getT (){return type;}
void setT (int t){type=t;}
point (){x=0; y=0; type=0;}
point (const point& p)
{
this->x=p.x;
this->y=p.y;
this->type=p.type;
}
point (int x, int y, int type)
{
this->x = x;
this->y = y;
this->type = type;
}
bool operator == (const point & p)
{
if (x==p.x && y==p.y && type==p.type)return true;
else return false;
}
};
#endif
Vector.h
#ifndef VECTOR_H
#define VECTOR_H
#include
using namespace std;
template
class Vector
{
T* V;
size_t n;
size_t capacity_m;
public:
Vector (size_t=0);
Vector (const Vector&);
size_t size ();
void reserve (size_t);
size_t begin ();
size_t end ();
size_t capacity ();
Vector& erase (size_t);
void swap (Vector&);
void push_back (T);
void resize (size_t);
~Vector ();
T& operator[](size_t);
};
#endif
ai_tree.cpp
#include
#include «Vector.h»
#include «point.h»
#include «life.h»
#include «ai_tree.h»
#include «Vector.cpp»
Tree* Tree: first (point** board)
{
Tree* pv=new Tree;
pv->points= new point*[8];
for (size_t i = 0; i < 8; i++)
pv->points[i]= new point[8];
pv->change_board (pv->points, board);
pv->rang=0;
pv->ai_Trees.resize (num_moves (board));
return pv;
}
Tree:~Tree ()
{
for (size_t i=0;i
delete ai_Trees[i];
ai_Trees=0;
}
Tree* Tree: insert_low (Tree *root, point** points)
{
Tree* pTree=NULL;
size_t num=0;
root->ai_Trees.resize (pTree->num_moves (points));
for (size_t i = 0; i < 8; i++)
{
for (size_t j = 0; j < 8; j++)
{
if (points[i][j]. getT ()==RED)
{
if ((j+1)<8&&(i+1)<8)
{
if ((points[i+1][j+1].getT ()==EMPTYCELL||
points[i+1][j+1].getT ()==BLUE)&&
(root->ai_Trees.size ()>num))
{
pTree=new Tree;
pTree->points=ai_copy_swap (points, j, i, j+1,i+1);
pTree->move_x=i;
pTree->move_y=j;
pTree->move_new_x=i+1;
pTree->move_new_y=j+1;
pTree->rang=ai_move_rating (points, i, j);
pTree->ai_Trees.resize (pTree->num_moves (points));
root->ai_Trees[num++]=pTree;
}
}
if ((j-1)<8&&(i+1)<8)
{
if ((points[i+1][j-1]. getT ()==EMPTYCELL||
points[i+1][j-1].getT ()==BLUE)&&
(root->ai_Trees.size ()>num))
{
pTree=new Tree;
pTree->points=ai_copy_swap (points, j, i, j-1,i+1);
pTree->rang=ai_move_rating (points, i, j);
pTree->move_x=i;
pTree->move_y=j;
pTree->move_new_x=i+1;
pTree->move_new_y=j-1;
pTree->ai_Trees.resize (pTree->num_moves (points));
root->ai_Trees[num++]=pTree;
}
}
}
if (points[i][j]. getT ()==REDKING&&
frag_king_ai (points, i, j))
{
pTree=new Tree;
pTree->rang=ai_move_rating (points, i, j);
pTree->move_x=i;
pTree->move_y=j;
pTree->ai_Trees.resize (pTree->num_moves (points));
root->ai_Trees[num++]=pTree;
}
}
}
return root;
}
Tree* Tree: insert_mid (Tree *root, point** points)
{
Tree* pTree=NULL;
size_t num=0;
root->ai_Trees.resize (pTree->num_moves_human (points));
for (size_t i = 0; i < 8; i++)
{
for (size_t j = 0; j < 8; j++)
{
if (points[i][j]. getT ()==BLUE)
{
if ((j-1)>0&&(j-1)<8&&(i-1)<8&&(i-1)>0)
{
if ((points[i-1][j-1].getT ()==EMPTYCELL||
points[i-1][j-1].getT ()==RED)&&
(root->ai_Trees.size ()>num))
{
pTree=new Tree;
pTree->points=ai_copy_swap (points, j, i, j-1,i-1);
pTree->move_x=i;
pTree->move_y=j;
pTree->move_new_x=i-1;
pTree->move_new_y=j-1;
pTree->rang=human_move_rating (points, i, j);
pTree->ai_Trees.resize (0);
root->ai_Trees[num++]=pTree;
}
}
if ((j+1)>0&&(j+1)<8&&(i-1)<8&&(i-1)>0)
{
if ((points[i-1][j+1]. getT ()==EMPTYCELL||
points[i-1][j+1].getT ()==RED)&&
(root->ai_Trees.size ()>num))
{
pTree=new Tree;
pTree->points=ai_copy_swap (points, j, i, j+1,i-1);
pTree->rang=human_move_rating (points, i, j);
pTree->move_x=i;
pTree->move_y=j;
pTree->move_new_x=i-1;
pTree->move_new_y=j+1;
pTree->ai_Trees.resize (0);
root->ai_Trees[num++]=pTree;
}
}
}
if (points[i][j]. getT ()==BLUEKING&&frag_king_ai (points, i, j))
{
pTree=new Tree;
pTree->rang=ai_move_rating (points, i, j);
pTree->move_x=i;
pTree->move_y=j;
pTree->move_new_x=i+1;
pTree->move_new_y=j-1;
pTree->ai_Trees.resize (pTree->num_moves (points));
root->ai_Trees[num++]=pTree;
}
}
}
return root;
}
void Tree: print (Tree* root, size_t level)
{
if (root)
{
for (size_t i=0;iai_Trees.size ();i++)
print (root->ai_Trees[i], level+1);
for (size_t i=0;i
cout<<" «;
cout<rang<
}
}
void Tree: change_board (point** board, point** new_board)
{
for (size_t i = 0; i < 8; i++)
for (size_t j = 0; j < 8; j++)
board[i][j]=new_board[i][j];
}
size_t Tree: num_moves_human (point** board)
{
size_t num=0;
for (size_t i = 0; i < 8; i++)
{
for (size_t j = 0; j < 8; j++)
{
if (board[i][j]. getT ()==BLUE)
if (board[i][j].getT ()==BLUEKING)
if (frag_king_ai (board, i, j)) num++;
}
}
return num;
}
size_t Tree: num_moves (point** board)
{
size_t num=0;
for (size_t i = 0; i < 8; i++)
{
for (size_t j = 0; j < 8; j++)
{
if (board[i][j]. getT ()==RED)
board[i+1][j+1].getT ()==BLUE)&&
board[i+1][j+1].getT ()≠RED)
num++;
if ((j-1)<8&&(i+1)<8)
if ((board[i+1][j-1].getT ()==EMPTYCELL
if (board[i][j].getT ()==REDKING)
if (frag_king_ai (board, i, j)) num++;
}
}
return num;
}
point** Tree: ai_copy_swap (point** board, size_t pos_x, size_t pos_y, size_t new_pos_x, size_t new_pos_y)
{
point** tmp;
point tmp1;
tmp= new point*[8];
for (size_t i = 0; i < 8; i++)
{
tmp[i]= new point[8];
for (size_t j = 0; j < 8; j++)
{
tmp[i][j]=board[i][j];
}
}
tmp1=tmp[pos_y][pos_x];
tmp[pos_y][pos_x]=tmp[new_pos_y][new_pos_x];
tmp[new_pos_y][new_pos_x]=tmp1;
return tmp;
}
int Tree: ai_move_rating (point** points, size_t i, size_t j)
{
int rank=0;
if (points[i][j]. getT ()==REDKING) rank+=25;
if (frag_king_ai (points, i, j)) rank+=100;
if (frag_comp_bool (points, i, j)) rank+=50;
if ((j-1)<8&&(j+1)<8&&(i+1)<8)
if ((i+1)<8&&(i+2)<8&&(j-1)<8&&(j+2)<8)
{
if (points[i+1][j+1]. getT ()==BLUE&&points[i+2][j+2].getT ()==BLUE) rank-=50;
}
if ((i-1)<8&&(j-1)<8&&(j-2)<8&&(i+2)<8)
{
if (points[i+1][j-1]. getT ()==BLUE&&points[i+2][j-2].getT ()==BLUE) rank-=50;
}
if ((i+1)<8&&(i+2)<8&&(j+1)<8)
{
if (points[i+1][j+1]. getT ()==EMPTYCELL&&points[i+2][j].getT ()==BLUE) rank+=3;
}
if ((i+1)<8&&(i+2)<8&&(j-1)<8&&(j+2)<8)
{
if (points[i+1][j-1]. getT ()==EMPTYCELL&&points[i+2][j+2].getT ()==BLUE) rank+=3;
}
if ((i+1)<8&&(i+2)<8&&(j-1)<8&&((j-2)<8||(j+2)<8))
return rank;
}
int Tree: human_move_rating (point** points, size_t i, size_t j)
{
int rank=0;
if (points[i][j]. getT ()==BLUEKING) rank+=5;
if (frag_king_ai (points, i, j)) rank+=100;
if ((j+1)<8&&(j-1)<8&&(i-1)<8)
if ((i-1)<8&&(i-2)<8&&(j+1)<8&&(j-2)<8)
{
if (points[i-1][j-1]. getT ()==RED&&points[i-2][j-2].getT ()==RED) rank-=5;
}
if ((i+1)<8&&(j+1)<8&&(j+2)<8&&(i-2)<8)
{
if (points[i-1][j+1]. getT ()==RED&&points[i-2][j+2].getT ()==BLUE) rank-=5;
}
if ((i-1)<8&&(i-2)<8&&(j-1)<8)
{
if (points[i-1][j-1]. getT ()==EMPTYCELL&&points[i-2][j].getT ()==RED) rank+=20;
}
if ((i-1)<8&&(i-2)<8&&(j+1)<8&&(j-2)<8)
{
if (points[i-1][j+1]. getT ()==EMPTYCELL&&points[i-2][j-2].getT ()==RED) rank+=20;
}
if ((i-1)<8&&(i-2)<8&&(j+1)<8&&(j+2)<8)
if (points[i-1][j+1]. getT ()==RED&&(points[i-2][j+2].getT ()==EMPTYCELL
return rank;
}
bool Tree: frag_king_ai (point** points, size_t x, size_t y)
{
if (points[x][y]. getT ()≠REDKING) return false;
for (size_t i=1;i<8;i++)
points[x-i][y-i]. getT ()==BLUEKING)
&&points[x-i-1][y-i-1].getT ()==EMPTYCELL)
return true;
if ((x+i+1)<8&&(y-i-1)<8&&(x-i-1)>=0)
if ((points[x+i][y-i]. getT ()==BLUE
return false;
}
bool Tree: frag_comp_bool (point** points, size_t x, size_t y)
{
if ((x+1)<8&&(x+2)<8&&(y-1)<8&&(y-2)<8)
if (points[x+1][y-1]. getT ()==BLUE&&
points[x+2][y-2].getT ()==EMPTYCELL)
return true;
if ((x+1)<8&&(x+2)<8&&(y+1)<8&&(y+2)<8)
if (points[x+1][y+1]. getT ()==BLUE&&
points[x+2][y+2].getT ()==EMPTYCELL)
return true;
return false;
}
Life.cpp
#include
#include «life.h»
#include
using namespace std;
Life:Life (QObject *parent)
: QObject (parent)
{
cells = 0;
points = 0;
setGridSize (QSize (8, 8));
}
Life:~Life ()
{
}
void Life: new_game ()
{
for (size_t i = 0; i < gridSize ().width (); i++)
{
for (size_t j = 0; j < gridSize ().height (); j++)
{
cells[i][j] = false;
if (i<=2&&(i+j)&1)
points[i][j]=point (i, j, RED);
else if (i>=5&&i<=7&&(i+j)&1)
points[i][j]=point (i, j, BLUE);
else if (i>=3&&i<=4&&(i+j)&1)
points[i][j]=point (i, j, EMPTYCELL);
else if (!(i+j)&1)
points[i][j]=point (i, j, WHITECELL);
}
}
}
bool Life: game_over ()
{
red_count=0;
blue_count=0;
for (size_t i = 0; i < gridSize ().width (); i++)
{
for (size_t j = 0; j < gridSize ().height (); j++)
{
if (points[i][j]. getT ()==RED) red_count++;
else if (points[i][j]. getT ()==BLUE)
blue_count++;
else if (points[i][j]. getT ()==BLUEKING)
blue_count++;
else if (points[i][j]. getT ()==REDKING)
red_count++;
}
}
if (red_count==0)
return true;
else if (blue_count==0)
return true;
return false;
}
void Life: setGridSize (const QSize &size)
{
if (cells ≠ 0) {
deleteCells ();
}
gridSizeProperty = size;
cells = new bool*[gridSize ().width ()];
points= new point*[gridSize ().width ()];
for (size_t i = 0; i < gridSize ().width (); i++)
{
cells[i] = new bool[gridSize ().height ()];
points[i]= new point[gridSize ().width ()];
for (size_t j = 0; j < gridSize ().height (); j++)
{
cells[i][j] = false;
if (i<=2&&(i+j)&1)
points[i][j]=point (i, j, RED);
else if (i>=5&&i<=7&&(i+j)&1)
points[i][j]=point (i, j, BLUE);
else if (i>=3&&i<=4&&(i+j)&1)
points[i][j]=point (i, j, EMPTYCELL);
else if (!(i+j)&1)
points[i][j]=point (i, j, WHITECELL);
}
}
}
QSize Life: gridSize () const
{
return gridSizeProperty;
}
bool Life: frag_comp (size_t x, size_t y)
{
if ((x+1)<8&&(x+2)<8&&(y-1)<8&&(y-2)<8)
{
if ((points[x+1][y-1]. getT ()==BLUE||
points[x+1][y-1].getT ()==BLUEKING)&&
points[x+2][y-2].getT ()==EMPTYCELL)
{
move (x, y, x+2,y-2);
points[(x+x+2)/2][(y+y-2)/2].setT (EMPTYCELL);
frag_comp (x+2,y-2);
return true;
}
}
if ((x+1)<8&&(x+2)<8&&(y+1)<8&&(y+2)<8)
{
if ((points[x+1][y+1]. getT ()==BLUE
||points[x+1][y-1].getT ()==BLUEKING)
&&points[x+2][y+2].getT ()==EMPTYCELL)
{
move (x, y, x+2,y+2);
points[(x+x+2)/2][(y+y+2)/2].setT (EMPTYCELL);
frag_comp (x+2,y+2);
return true;
}
}
return false;
}
bool Life: frag (size_t x, size_t y, size_t new_x, size_t new_y)
bool Life: frag_move (size_t x, size_t y, size_t new_x, size_t new_y)
{
if (points[x][y]. getT ()==BLUE||points[x][y].getT ()==BLUEKING)
{
if (points[x][y].getT ()==BLUEKING)
{
for (size_t i=1 ;i<8;i++)
{
if ((x+i)<8&&(y+i)<8)
{
if (points[x+i][y+i]. getT ()==RED||
points[x+i][y+i].getT ()==REDKING)
{
move (x, y, new_x, new_y);
points[x+i][y+i].setT (EMPTYCELL);
return true;
}
}
if ((x-i)<8&&(y-i)<8)
{
if (points[x-i][y-i]. getT ()==RED||
points[x-i][y-i].getT ()==REDKING)
{
move (x, y, new_x, new_y);
points[x-i][y-i].setT (EMPTYCELL);
return true;
}
}
if ((x+i)<8&&(y-i)<8)
{
if (points[x+i][y-i]. getT ()==RED||
points[x+i][y-i].getT ()==REDKING)
{
move (x, y, new_x, new_y);
points[x+i][y-i].setT (EMPTYCELL);
return true;
}
}
if ((x-i)<8&&(y+i)<8)
{
if (points[x-i][y+i]. getT ()==BLUE&&
points[x-i][y+i].getT ()==EMPTYCELL)
{
move (x, y, new_x, new_y);
points[x-i][y+i].setT (EMPTYCELL);
return true;
}
}
}
}
else if (points[x][y]. getT ()==BLUE)
{
move (x, y, new_x, new_y);
points[(x+new_x)/2][(y+new_y)/2].setT (EMPTYCELL);
if ((new_y-2)>0&&(new_y-2)<8&&(new_x-2)<8&&(new_x-2)>=0)
if (frag (new_x, new_y, new_x-2,new_y-2))
frag_move (new_x, new_y, new_x-2,new_y-2);
if ((new_y+2)>0&&(new_y+2)<8&&(new_x-2)<8&&(new_x-2)>=0)
if (frag (new_x, new_y, new_x-2,new_y+2))
frag_move (new_x, new_y, new_x-2,new_y+2);
return true;
}
}
return false;
}
bool Life: frag_king (size_t x, size_t y)
{
if (points[x][y]. getT ()≠REDKING) return false;
for (size_t i=1;i<8;i++)
{
if ((x+i+1)<8&&(y+i+1)<8)
{
if (points[x+i][y+i]. getT ()==RED) continue;
if ((points[x+i][y+i]. getT ()==BLUE||
points[x+i][y+i].getT ()==BLUEKING)&&
points[x+i-1][y+i-1].getT ()≠BLUE&&
points[x+i+1][y+i+1].getT ()==EMPTYCELL)
{
move (x, y, x+i+1,y+i+1);
points[x+i][y+i].setT (EMPTYCELL);
frag_king (x+i+1,y+i+1);
return true;
}
}
if ((x-i-1)<8&&(y-i-1)<8)
{
if (points[x-i][y-i]. getT ()==RED) continue;
if ((points[x-i][y-i]. getT ()==BLUE||
points[x-i][y-i].getT ()==BLUEKING)&&
points[x-i-1][y-i-1].getT ()≠BLUE
&&points[x-i-1][y-i-1].getT ()==EMPTYCELL)
{
move (x, y, x-i-1,y-i-1);
points[x-i][y-i].setT (EMPTYCELL);
frag_king (x-i-1,y-i-1);
return true;
}
}
if ((x+i+1)<8&&(y-i-1)<8)
{
if (points[x+i][y-i]. getT ()==RED) continue;
if ((points[x+i][y-i]. getT ()==BLUE||
points[x+i][y-i].getT ()==BLUEKING)&&
points[x+i-1][y-i-1].getT ()≠BLUE
&&points[x+i+1][y-i-1].getT ()==EMPTYCELL)
{
move (x, y, x+i+1,y-i-1);
points[x+i][y-i].setT (EMPTYCELL);
frag_king (x+i+1,y-i-1);
return true;
}
}
if ((x-i-1)<8&&(y+i+1)<8)
{
if (points[x-i][y+i]. getT ()==RED) continue;
if ((points[x-i][y+i]. getT ()==BLUE||
points[x-i][y+i].getT ()==BLUEKING)&&
points[x-i-1][y+i-1].getT ()≠BLUE
&&points[x-i-1][y+i+1].getT ()==EMPTYCELL)
{
move (x, y, x-i-1,y+i+1);
points[x-i][y+i].setT (EMPTYCELL);
frag_king (x-i-1,y+i+1);
return true;
}
}
}
return false;
}
void Life: refresh ()
{
for (size_t i = 0; i < gridSize ().width (); i++)
for (size_t j = 0; j < gridSize ().height (); j++)
cells[i][j]=false;
}
bool Life: move_ai_king (size_t x, size_t y)
{
if (points[x][y]. getT ()==REDKING)
{
if ((x-1)>0&&(y-1)<8&&(x-1)<8&&(x-1)>0)
if (points[x-1][y-1].getT ()==EMPTYCELL&&
points[x-1][y-1].getT ()≠RED)
{
move (x, y, x-1,y-1);
return true;
}
if ((y+1)>0&&(y+1)<8&&(x-1)<8&&(x-1)>0)
if (points[x-1][y+1]. getT ()==EMPTYCELL&&
points[x-1][y+1].getT ()≠RED)
{
move (x, y, x-1,y+1);
return true;
}
}
return false;
}
bool Life: move (size_t x, size_t y, size_t new_x, size_t new_y)
{
point buf;
buf=points[new_x][new_y];
points[new_x][new_y]=points[x][y];
points[x][y]=buf;
return true;
}
void Life: setCell (const QPoint &pos, bool value)
{
if (gridSize ().width () > pos. x () &&
gridSize ().height () > pos. y ())
{
cells[pos.x ()][pos.y ()] = value;
}
}
bool Life: cell (const QPoint &pos) const
{
if (gridSize ().width () > pos. x () &&
gridSize ().height () > pos. y ())
{
return cells[pos.x ()][pos.y ()];
}
return false;
}
bool Life: Cell_King (size_t x, size_t y)
{
if (points[x][y]. getT ()==RED&&x==7)
{
points[x][y].setT (REDKING);
return true;
}
else if (points[x][y]. getT ()==BLUE&&x==0)
{
points[x][y].setT (BLUEKING);
return true;
}
return false;
}
void Life: deleteCells ()
{
for (size_t i = 0; i < gridSize ().width (); i++)
{
delete [] cells[i];
delete [] points[i];
}
delete [] cells;
delete [] points;
cells = 0;
points= 0;
}
LifeWidget.cpp
#include
#include «life.h»
#include «lifewidget.h»
#include «ai_tree.h»
#include «point.h»
#include
#include «mainwindow.h»
using namespace std;
LifeWidget:LifeWidget (QWidget *parent)
: QWidget (parent)
{
life = new Life (this);
player=BLUE;
cout_moves=1;
click1=FALSE;
click2=FALSE;
state_now=-1;
game_level=3;
setCellSize (70);
setGridSize (QSize (8, 8));
game=game->first (life->points);
p = new point*[8];
for (size_t i = 0; i < 8; i++)
{
p[i] = new point[8];
for (size_t j = 0; j < 8; j++)
p[i][j]=point ();
}
game->change_board (p, life->points);
add_event_history (p);
}
LifeWidget:~LifeWidget ()
{
for (size_t i = 0; i < 8; i++)
delete p[i];
}
void LifeWidget: add_event_history (point** new_move)
{
point** tmp2=new_move;
tmp2 = new point*[8];
for (size_t i = 0; i < 8; i++)
{
tmp2[i] = new point[8];
for (size_t j = 0; j < 8; j++)
tmp2[i][j]=new_move[i][j];
}
history_moves.push_back (tmp2);
state_now++;
}
void LifeWidget: set_game_level (size_t level)
{
if (level==1)
game_level=1;
else if (level==0)
game_level=0;
}
void LifeWidget: history_up ()
{
state_now++;
if (state_now>=history_moves.size ())
{
state_now—;
return;
}
else
{
point **p=history_moves[state_now];
game->change_board (life->points, p);
player=BLUE;
update ();
}
}
void LifeWidget: history_down ()
{
state_now—;
if (state_now<=0)
{
state_now++;
return;
}
else
{
point **p=history_moves[state_now];
game->change_board (life->points, p);
player=BLUE;
update ();
}
}
void LifeWidget: setGridSize (const QSize &size)
{
life->setGridSize (size);
adjustSize ();
update ();
}
QSize LifeWidget: gridSize () const
{
return life->gridSize ();
}
void LifeWidget: setCellSize (int size)
{
cellSizeProperty = size;
adjustSize ();
update ();
}
int LifeWidget: cellSize () const
{
return cellSizeProperty;
}
QSize LifeWidget: minimumSizeHint () const
{
return QSize (gridSize ().width () * cellSize (), gridSize ().height () * cellSize ());
}
QSize LifeWidget: sizeHint () const
{
return minimumSizeHint ();
}
void LifeWidget: mousePressEvent (QMouseEvent *event)
{
if (!(game_level==1||game_level==0)) return;
QPoint pos = QPoint (event->pos ().x () / cellSize (), event->pos ().y () / cellSize ());
if (player==BLUE)
{
if ((pos.y ()+pos.x ())&1&&(life->points[pos.y ()][pos.x ()]. getT ()==BLUE||
life->points[pos.y ()][pos.x ()].getT ()==BLUEKING))
{
if (event->button () == Qt: RightButton)
{
click1=false;
click2=false;
life->refresh ();
update ();
return;
}
}
if (click1==false&&(pos.y ()+pos.x ())&1&&(life->points[pos.y ()][pos.x ()]. getT ()==BLUE||
life->points[pos.y ()][pos.x ()].getT ()==BLUEKING))
{
click1=true;
if (event->button () == Qt: LeftButton && !life->cell (pos)&&click1)
{
life->setCell (pos, true);
point click (pos.y (), pos. x (), life->points[pos.y ()][pos.x ()]. getT ());
life->tmp=click;
click2=true;
update ();
return;
}
}
else if (event->button () == Qt: LeftButton&&!life->cell (pos)&&click1&&click2&&(pos.y ()+pos.x ())&1
&&life->points[pos.y ()][pos.x ()]. getT ()==EMPTYCELL)
{
life->setCell (pos, true);
if (life->points[life->tmp.getX ()][life->tmp.getY ()]. getT ()==BLUEKING)
{
game->change_board (p, life->points);
add_event_history (p);
if (life->frag_move (life->tmp.getX (), life->tmp.getY (), pos. y (), pos. x ()))
{
life->refresh ();
click1=false;
click2=false;
player=RED;
update ();
return;
}
else
{
life->move (life->tmp.getX (), life->tmp.getY (), pos. y (), pos. x ());
life->refresh ();
click1=false;
click2=false;
player=RED;
update ();
return;
}
}
if (life->frag (life->tmp.getX (), life->tmp.getY (), pos. y (), pos. x ()))
{
game->change_board (p, life->points);
add_event_history (p);
if ((life->tmp.getX ()-2)==pos.y ()&&((life->tmp.getY ()-2)==pos.x ()||(life->tmp.getY ()+2)==pos.x ()))
{
life->frag_move (life->tmp.getX (), life->tmp.getY (), pos. y (), pos. x ());
life->refresh ();
click1=false;
click2=false;
player=RED;
update ();
if (life->game_over ())
{
life->new_game ();
player=BLUE;
return;
}
}
else
{
life->refresh ();
click1=false;
click2=false;
player=BLUE;
}
}
else
{
game->change_board (p, life->points);
add_event_history (p);
if ((life->tmp.getX ()-1)==pos.y ()&&((life->tmp.getY ()-1)==pos.x ()||(life->tmp.getY ()+1)==pos.x ()))
{
life->move (life->tmp.getX (), life->tmp.getY (), pos. y (), pos. x ());
life->refresh ();
click1=false;
click2=false;
player=RED;
}
else
{
click1=false;
click2=false;
player=BLUE;
life->refresh ();
}
}
}
}
}
void LifeWidget: Draw_Cell (QPainter *painter, QBrush PenBrush, int pen_size, QBrush RectBrush, int x0, int y0, int size)
{
painter->setRenderHint (QPainter:Antialiasing);
painter->setPen (QPen (PenBrush, pen_size, Qt: SolidLine));
painter->setBrush (RectBrush);
painter->drawRect (x0, y0, size, size);
}
void LifeWidget: Draw_Ellipse (QPainter *painter, QBrush PenBrush, int pen_size, QBrush RectBrush, int x0, int y0, int size)
{
painter->setRenderHint (QPainter:Antialiasing);
painter->setPen (QPen (PenBrush, pen_size, Qt: SolidLine));
painter->setBrush (RectBrush);
painter->drawEllipse (x0, y0, size, size);
}
void LifeWidget: ai_low ()
{
if (player==RED)
{
game->insert_low (game, life->points);
int max=game->ai_Trees[0]->rang;
int ii=0;
for (size_t i=0;iai_Trees.size ();i++)
{
if (game->ai_Trees[i]->rang>max)
{
ii=i;
max=game->ai_Trees[i]->rang;
}
}
game=game->ai_Trees[ii];
if (game->frag_king_ai (life->points, game->move_x, game->move_y))
{
life->frag_king (game->move_x, game->move_y);
player=BLUE;
update ();
return;
}
else if (life->frag_comp (game->move_x, game->move_y))
{
player=BLUE;
update ();
return;
}
else if (life->move_ai_king (game->move_x, game->move_y))
{
player=BLUE;
update ();
return;
}
else
{
life->move (game->move_x, game->move_y, game->move_new_x, game->move_new_y);
player=BLUE;
update ();
return;
}
player=BLUE;
update ();
}
}
void LifeWidget: ai_mid ()
{
if (player==RED)
{
Tree* tmp=game;
cout_moves++;
game->insert_low (game, life->points);
int maxI=game->ai_Trees[0]->rang;
int iii=0;
for (size_t i=0;iai_Trees.size ();i++)
{
if (game->ai_Trees[i]->rang>maxI)
{
iii=i;
maxI=game->ai_Trees[i]->rang;
}
}
if (game->frag_king_ai (life->points, game->ai_Trees[iii]->move_x, game->ai_Trees[iii]->move_y))
{
life->frag_king (game->ai_Trees[iii]->move_x, game->ai_Trees[iii]->move_y);
player=BLUE;
update ();
return;
}
else if (life->frag_comp (game->ai_Trees[iii]->move_x, game->ai_Trees[iii]->move_y))
{
player=BLUE;
update ();
return;
}
else if (life->move_ai_king (game->ai_Trees[iii]->move_x, game->ai_Trees[iii]->move_y))
{
player=BLUE;
update ();
return;
}
for (size_t i=0;iai_Trees.size ();i++)
game->insert_mid (game->ai_Trees[i], game->ai_Trees[i]->points);
Vector childs_sum (game->ai_Trees.size ());
for (size_t i=0;iai_Trees.size ();i++)
for (size_t j=0;jai_Trees[i]->ai_Trees.size ();j++)
childs_sum[i]+=game->ai_Trees[i]->ai_Trees[j]->rang;
int ii=0;
int max=childs_sum[0];
for (size_t i=0;i
if (childs_sum[i]>max)
{
ii=i;
max=childs_sum[i];
}
game=game->ai_Trees[ii];
if (1)
{
life->move (game->move_x, game->move_y, game->move_new_x, game->move_new_y);
player=BLUE;
update ();
return;
}
player=BLUE;
update ();
}
}
void LifeWidget: paintEvent (QPaintEvent* /*event*/)
{
QPainter p (this);
if (game_level==1) ai_mid ();
else if (game_level==0) ai_low ();
if (life->game_over ())
{
life->new_game ();
player=BLUE;
return;
}
for (int i = 0; i < gridSize ().width (); i++) //KING
for (int j = 0; j < gridSize ().height (); j++)
life->Cell_King (i, j);
for (int i = 0; i < gridSize ().width (); i++) //ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΏΠΎΠ»Ρ
{
for (int j = 0; j < gridSize ().height (); j++)
{
if ((i+j)&1)
{
Draw_Cell (&p, Qt: black, 0, Qt:gray, i * cellSize (), j * cellSize (), cellSize ());
if (life->points[j][i]. getT ()==RED)
{
Draw_Ellipse (&p, Qt: black, 2, Qt:red, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
else if (life->points[j][i]. getT ()==BLUE)
{
Draw_Ellipse (&p, Qt: black, 2, Qt:blue, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
else if (life->points[j][i]. getT ()==REDKING)
{
Draw_Ellipse (&p, Qt: green, 4, Qt:red, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
else if (life->points[j][i]. getT ()==BLUEKING)
{
Draw_Ellipse (&p, Qt: green, 4, Qt:blue, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
}
else if (life->points[j][i]. getT ()==WHITECELL)
{
Draw_Cell (&p, Qt: black, 0, Qt:white, i * cellSize (), j * cellSize (), cellSize ());
for (int i = 0; i < gridSize ().width (); i++) //ΡΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΠΆΠ΅Π»ΡΠΎΠΉ ΠΊΠ»Π΅ΡΠΊΠΈ
for (int j = 0; j < gridSize ().height (); j++)
if (life->cell (QPoint (i, j))&&(i+j)&1)
{
Draw_Cell (&p, Qt: yellow, 6, Qt:gray, i * cellSize (), j * cellSize (), cellSize ());
if (life->points[j][i]. getT ()==RED)
{
Draw_Ellipse (&p, Qt: black, 2, Qt:red, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
else if (life->points[j][i]. getT ()==BLUE)
{
Draw_Ellipse (&p, Qt: black, 2, Qt:blue, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
else if (life->points[j][i]. getT ()==REDKING)
{
Draw_Ellipse (&p, Qt: green, 4, Qt:red, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
else if (life->points[j][i]. getT ()==BLUEKING)
{
Draw_Ellipse (&p, Qt: green, 4, Qt:blue, i * cellSize ()+5,j * cellSize ()+5,cellSize ()-10);
}
}
update ();
}
MainWindow.cpp
#include
#include «mainwindow.h»
#include «lifewidget.h»
#include «ai_tree.h»
#include «point.h»
MainWindow:MainWindow ()
{
QScrollArea scroll;
life = new LifeWidget (&scroll);
setCentralWidget (life);
scroll.show ();
life->show ();
life->setCellSize (70);
createActions ();
createMenus ();
createToolBars ();
createStatusBar ();
setWindowTitle (tr («Checkers»));
setUnifiedTitleAndToolBarOnMac (true);
}
void MainWindow: newLetter ()
{
life->history_down ();
update ();
}
void MainWindow: save ()
{
life->history_up ();
update ();
}
void MainWindow: about ()
{
QMessageBox:about (this, tr («About Checkers»),
tr («Checkers //»
" NN, 2010"));
}
void MainWindow: level_mid ()
{
life->set_game_level (1);
}
void MainWindow: level_low ()
{
life->set_game_level (0);
}
void MainWindow: createActions ()
{
newLetterAct = new QAction (QIcon («save.png»), tr («&Back»),
this);
newLetterAct->setShortcuts (QKeySequence:New);
newLetterAct->setStatusTip (tr («Back_move»));
connect (newLetterAct, SIGNAL (triggered ()), this, SLOT (newLetter ()));
saveAct = new QAction (QIcon («new.png»), tr («&Forward»), this);
saveAct->setShortcuts (QKeySequence:Save);
saveAct->setStatusTip (tr («Forward_move»));
connect (saveAct, SIGNAL (triggered ()), this, SLOT (save ()));
low = new QAction (QIcon («low.png»), tr («low_level»), this);
low->setStatusTip (tr («low_level»));
connect (low, SIGNAL (triggered ()), this, SLOT (level_low ()));
mid = new QAction (QIcon («mid.png»), tr («&mid_level»), this);
mid->setStatusTip (tr («mid_level»));
connect (mid, SIGNAL (triggered ()), this, SLOT (level_mid ()));
quitAct = new QAction (tr («&Quit»), this);
quitAct->setShortcuts (QKeySequence:Quit);
quitAct->setStatusTip (tr («Quit the application»));
connect (quitAct, SIGNAL (triggered ()), this, SLOT (close ()));
aboutAct = new QAction (tr («&About»), this);
aboutAct->setStatusTip (tr («Show the application’s About box»));
connect (aboutAct, SIGNAL (triggered ()), this, SLOT (about ()));
aboutQtAct = new QAction (tr («About &Qt»), this);
aboutQtAct->setStatusTip (tr («Show the Qt library’s About box»));
connect (aboutQtAct, SIGNAL (triggered ()), qApp, SLOT (aboutQt ()));
}
void MainWindow: createMenus ()
{
fileMenu = menuBar ()->addMenu (tr («&File»));
fileMenu->addAction (newLetterAct);
fileMenu->addAction (saveAct);
fileMenu->addSeparator ();
fileMenu->addAction (low);
fileMenu->addAction (mid);
fileMenu->addSeparator ();
fileMenu->addAction (quitAct);
menuBar ()->addSeparator ();
helpMenu = menuBar ()->addMenu (tr («&Help»));
helpMenu->addAction (aboutAct);
helpMenu->addAction (aboutQtAct);
}
void MainWindow: createToolBars ()
{
fileToolBar = addToolBar (tr («File»));
fileToolBar->addAction (newLetterAct);
fileToolBar->addAction (saveAct);
}
void MainWindow: createStatusBar ()
{
statusBar ()->showMessage (tr («Ready»));
}
Vector.cpp
#include
#include «Vector.h»
using namespace std;
template
Vector:~Vector ()
{
delete[] V;
V=0;
}
template
size_t Vector: size ()
{
return n;
}
template
size_t Vector: begin ()
{
return 0;
}
template
size_t Vector: end ()
{
return n;
}
template
size_t Vector: capacity ()
{
return capacity_m;
}
template
void Vector: swap (Vector& Vect)
{
std:swap (V, Vect. V);
std:swap (n, Vect. n);
std:swap (capacity_m, Vect. capacity_m);
}
template
Vector:Vector (const Vector& Vect)
{
n=Vect.n;
capacity_m=Vect.capacity_m;
V=new T[n];
for (size_t i=0;i
(*this)[i]=Vect.V[i];
}
template
T& Vector: operator [](size_t i)
{
if (i
throw out_of_range («vector index»);
}
template
Vector:Vector (size_t new_size)
{
n=new_size;
capacity_m=new_size;
V=new T[new_size];
for (size_t i=0;i
(*this)[i]=T ();
}
template
Vector& Vector: erase (size_t k)
{
if (k>=n) throw out_of_range («vector index»);
Vector buf=*this;
n—;
for (size_t i=0;i
if (i≠k)(*this)[i]=buf[i];
else
{
(*this)[i]=buf[i+1];
k++;
}
return *this;
}
template
void Vector: push_back (T new_item)
{
if (size () == capacity ()) reserve (capacity () * 2);
(*this)[n++] = new_item;
}
template
void Vector: resize (size_t new_size)
{
if (new_size <= size ())
{
n=new_size;
return;
}
if (new_size > capacity ())
reserve (new_size * 2);
delete[] V;
V=new T[new_size];
while (n ≠ new_size)
(*this)[n++] = T ();
}
template
void Vector: reserve (size_t new_cap)
{
if (new_cap <= capacity ()) return;
Vector buf;
buf.V = new T[new_cap];
buf.capacity_m = new_cap;
buf.n = n;
for (size_t i=0; i
buf[i] = (*this)[i];
buf.swap (*this);
}
Π Π΅Π·ΡΠ»ΡΡΠ°ΡΡ ΡΠ°Π±ΠΎΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ