IPB
ЛогинПароль:

> Две лисы и 20 кур
is1988
сообщение 11.03.2008 2:46
Сообщение #1





Группа: Пользователи
Сообщений: 3
Пол: Мужской

Репутация: -  0  +


На поле указанной формы находятся две лисы и 20 кур



Л Л
К К К К К К К
К К К К К К К
К К К
К К К
Куры могут перемещаться на один шаг вверх, влево или вправо, но не назад и не по диагонали. Лисы могут перемещаться на один шаг влево, вправо, вверх и вниз. Лиса может съесть курицу, как в игре в шашки: если в горизонтальном или вертикальном направлении за курицей на один шаг следует свободное поле, то лиса перепрыгивает через курицу и ест ее. Лисы всегда обязаны есть, и когда у них бывает выбор, они обязаны осуществить "наиболее длинное поедание". Если два приема пищи имеют одинаковую длину – выбирается любой из них.
Необходимо написать программу, играющую за лис. Игрок перемещает кур. Партнеры играют по очереди, причем куры начинают. Они выигрывают партию, если девяти из них удается занять 9 полей, образующих верхний квадрат поля. Лисы выигрывают, если им удается съесть 12 кур, т.к. в этом случае будет недостаточно оставшихся кур, чтобы занять 9 верхних полей.
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 
 
 Ответить  Открыть новую тему 
Ответов
Гость
сообщение 8.04.2008 1:04
Сообщение #2


Гость






 ! 
Теги !!!



 
//--------------------------------------------------------------------------- 

#include <vcl.h> 
#pragma hdrstop 

#include "Unit1.h" 
//--------------------------------------------------------------------------- 
#pragma package(smart_init) 
#pragma resource "*.dfm" 
TForm1 *Form1; 
int OneStep[20][2]; 
int Count=0; 
int NumberHens=20; 
int Foxs[2][2]; 
bool Sate[2]={false,false}; 
//--------------------------------------------------------------------------- 
__fastcall TForm1::TForm1(TComponent* Owner) 
        : TForm(Owner) 
{ 
  StringGrid1->Cells[2][2]="Л"; 
  StringGrid1->Cells[4][2]="Л"; 
  Foxs[0][0]=2; 
  Foxs[0][1]=2; 
  Foxs[1][0]=4; 
  Foxs[1][1]=2; 
  for (int i=0;i<7;i++) 
    for (int j=3;j<5;j++) 
      StringGrid1->Cells[i][j]="К"; 
  for (int i=5;i<7;i++) 
    for (int j=2;j<5;j++) 
      StringGrid1->Cells[j][i]="К"; 
  StringGrid1->Col=3; 
  StringGrid1->Row=3; 
  for (int i=0;i<20;i++) 
    for (int j=0;j<2;j++) 
      OneStep[i][j]=0; 

} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, 
      int ARow, TRect &Rect, TGridDrawState State) 
{ 
  StringGrid1->Canvas->Brush->Color=clBlack; 
  StringGrid1->Canvas->Rectangle(0,0,StringGrid1->DefaultColWidth*2+2,StringGrid1->DefaultRowHeight*2+2); 
  StringGrid1->Canvas->Rectangle(0,StringGrid1->DefaultRowHeight*5+4,StringGrid1->DefaultColWidth*2+2,StringGrid1->DefaultRowHeight*7+7); 
  StringGrid1->Canvas->Rectangle(StringGrid1->DefaultColWidth*5+4,0,StringGrid1->DefaultColWidth*7+7,StringGrid1->DefaultRowHeight*2+2); 
  StringGrid1->Canvas->Rectangle(StringGrid1->DefaultColWidth*5+4,StringGrid1->DefaultRowHeight*5+4,StringGrid1->DefaultColWidth*7+7,StringGrid1->DefaultRowHeight*7+7); 
} 
//--------------------------------------------------------------------------- 

void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol, 
      int ARow, bool &CanSelect) 
{ 
  if ((ACol==1)&&(ARow==1)||(ACol==1)&&(ARow==0)||(ACol==0)&&(ARow==1)||(ACol==0)&&(ARow==0)|| 
      (ACol==5)&&(ARow==0)||(ACol==5)&&(ARow==1)||(ACol==6)&&(ARow==0)||(ACol==6)&&(ARow==1)|| 
      (ACol==0)&&(ARow==5)||(ACol==0)&&(ARow==6)||(ACol==1)&&(ARow==5)||(ACol==1)&&(ARow==6)|| 
      (ACol==5)&&(ARow==5)||(ACol==5)&&(ARow==6)||(ACol==6)&&(ARow==5)||(ACol==6)&&(ARow==6)) 
    CanSelect=false; 
} 
//--------------------------------------------------------------------------- 

void __fastcall TForm1::StringGrid1KeyDown(TObject *Sender, WORD &Key, 
      TShiftState Shift) 
{ 
  bool check=true; 
  for (int i=0;i<NumberHens;i++) 
  { 
    if ((OneStep[i][0]==StringGrid1->Col)&&(OneStep[i][1]==StringGrid1->Row)) 
    { 
      check=false; 
      break; 
    } 
  } 
  if (check) 
  { 
    switch(Key) 
    { 
    case 38:     //UP 
      if ((StringGrid1->Row>0)&&((StringGrid1->Row>2)||(StringGrid1->Col>1))&&((StringGrid1->Row>2)||(StringGrid1->Col<5))) 
      { 
        if ((StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=="К")&& 
            (StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row-1]=="")) 
        { 
          StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=""; 
          StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row-1]="К"; 
          OneStep[Count][0]=StringGrid1->Col; 
          OneStep[Count][1]=StringGrid1->Row-1; 
          Count++; 
        } 
      } 
    break; 
    case 37:     //Left 
      if ((StringGrid1->Col>0)&&((StringGrid1->Col>2)||(StringGrid1->Row>1))&&((StringGrid1->Col>2)||(StringGrid1->Row<5))) 
      { 
        if ((StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=="К")&& 
            (StringGrid1->Cells[StringGrid1->Col-1][StringGrid1->Row]=="")) 
        { 
          StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=""; 
          StringGrid1->Cells[StringGrid1->Col-1][StringGrid1->Row]="К"; 
          OneStep[Count][0]=StringGrid1->Col-1; 
          OneStep[Count][1]=StringGrid1->Row; 
          Count++; 
        } 
      } 
    break; 
    case 39:    //Right 
      if ((StringGrid1->Col<6)&&((StringGrid1->Col<4)||(StringGrid1->Row>1))&&((StringGrid1->Col<4)||(StringGrid1->Row<5))) 
      { 
        if ((StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=="К")&& 
            (StringGrid1->Cells[StringGrid1->Col+1][StringGrid1->Row]=="")) 
        { 
          StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=""; 
          StringGrid1->Cells[StringGrid1->Col+1][StringGrid1->Row]="К"; 
          OneStep[Count][0]=StringGrid1->Col+1; 
          OneStep[Count][1]=StringGrid1->Row; 
          Count++; 
        } 
      } 
    break; 
    } 
  } 
  Edit1->Text=NumberHens-Count; 
} 
//--------------------------------------------------------------------------- 

void __fastcall TForm1::Button2Click(TObject *Sender) 
{ 
  Form1->Close();        
} 
//--------------------------------------------------------------------------- 

void __fastcall TForm1::Button1Click(TObject *Sender) 
{ 
  for (int i=0;i<2;i++) 
    KillHen(i); 
  for (int i=0;i<20;i++) 
    for (int j=0;j<2;j++) 
      OneStep[i][j]=0; 
  Count=0; 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::MinusHen(int i) 
{ 
  NumberHens--; 
  Edit2->Text=NumberHens; 
  Edit1->Text=NumberHens; 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::KillHen(int i) 
{ 
  bool check=false; 
  if (Foxs[i][0]>1) 
  { 
    if ((StringGrid1->Cells[Foxs[i][0]-1][Foxs[i][1]]=="К")&&(StringGrid1->Cells[Foxs[i][0]-2][Foxs[i][1]]=="")) 
    { 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]]=""; 
      StringGrid1->Cells[Foxs[i][0]-1][Foxs[i][1]]=""; 
      StringGrid1->Cells[Foxs[i][0]-2][Foxs[i][1]]="Л"; 
      Foxs[i][0]=Foxs[i][0]-2; 
      MinusHen(i); 
      check=true; 
    } 
  } 
  if (Foxs[i][0]<5) 
  { 
    if ((StringGrid1->Cells[Foxs[i][0]+1][Foxs[i][1]]=="К")&&(StringGrid1->Cells[Foxs[i][0]+2][Foxs[i][1]]=="")) 
    { 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]]=""; 
      StringGrid1->Cells[Foxs[i][0]+1][Foxs[i][1]]=""; 
      StringGrid1->Cells[Foxs[i][0]+2][Foxs[i][1]]="Л"; 
      Foxs[i][0]=Foxs[i][0]+2; 
      MinusHen(i); 
      check=true; 
    } 
  } 
  if (Foxs[i][1]<5) 
  { 
    if ((StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]+1]=="К")&&(StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]+2]=="")) 
    { 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]]=""; 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]+1]=""; 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]+2]="Л"; 
      Foxs[i][1]=Foxs[i][1]+2; 
      MinusHen(i); 
      check=true; 
    } 
  } 
  if (Foxs[i][1]>1) 
  { 
    if ((StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]-1]=="К")&&(StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]-2]=="")) 
    { 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]]=""; 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]-1]=""; 
      StringGrid1->Cells[Foxs[i][0]][Foxs[i][1]-2]="Л"; 
      Foxs[i][1]=Foxs[i][1]-2; 
      MinusHen(i); 
      check=true; 
    } 
  } 
  if (check) 
    KillHen(i); 
} 
//---------------------------------------------------------------------------


НУЖНО ПЕРЕДЕЛАТЬ В DELPHI

Сообщение отредактировано: klem4 - 8.04.2008 7:23
 К началу страницы 
+ Ответить 

Сообщений в этой теме


 Ответить  Открыть новую тему 
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 

- Текстовая версия 29.07.2025 8:59
Хостинг предоставлен компанией "Веб Сервис Центр" при поддержке компании "ДокЛаб"