ΠŸΠΎΠΌΠΎΡ‰ΡŒ Π² написании студСнчСских Ρ€Π°Π±ΠΎΡ‚
АнтистрСссовый сСрвис

Π Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹ ΠΈΠ³Ρ€Ρ‹ Π² шашки

ΠšΠΎΠ½Ρ‚Ρ€ΠΎΠ»ΡŒΠ½Π°ΡΠŸΠΎΠΌΠΎΡ‰ΡŒ Π² Π½Π°ΠΏΠΈΡΠ°Π½ΠΈΠΈΠ£Π·Π½Π°Ρ‚ΡŒ ΡΡ‚ΠΎΠΈΠΌΠΎΡΡ‚ΡŒΠΌΠΎΠ΅ΠΉ Ρ€Π°Π±ΠΎΡ‚Ρ‹

Π’ Π΄Π°Π½Π½ΠΎΠΉ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ΅ основным классом являСтся класс 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);

}

Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Ρ‹ Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹

ΠŸΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ вСсь тСкст
Π—Π°ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ Ρ„ΠΎΡ€ΠΌΡƒ Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ Ρ€Π°Π±ΠΎΡ‚ΠΎΠΉ