11 Temmuz 2014, 10:26
#1 Çevrimdışı
Kullanıcıların profil bilgileri misafirlere kapatılmıştır.
Dört At Problemi ve Simülasyonu
Bu proje 3*3 bir matriste bulunan konumları kullanıcı tarafından belirlenen 2 adet siyah ve 2 adet beyaz atın satranç kuralları dahilinde(at hareketine göre atlar üst üste gelmeyecek şekilde) yer değiştirme işlemini çözen ve at hareketlerini simülasyon ile gösteren programdır.
Programda öncelikli olarak siyah ve beyaz atları karelere sürükleyip bırakın daha sonra program siyah ile beyaz atların yerlerini değiştirecektir.
Kod: Kodu kopyalamak için üzerine çift tıklayın!
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int yukari()
{
Form1->Image20->Top-=5;
}
int asagi()
{
Form1->Image20->Top+=5;
}
int saga()
{
Form1->Image20->Left+=5;
}
int sola()
{
Form1->Image20->Left-=5;
}
int al=0; int ak=0;
int a=0; int b=0; int c=0; int d=0; int e=0; int f=0; int z=0;
void __fastcall TForm1::FormCreate(TObject *Sender)
{ Image20->Visible=false; Image20->Name="ad";
BitBtn1->Enabled=false;
Image5->Enabled=false; Image11->Enabled=false;
Image1->Picture=Image11->Picture;
Image2->Picture=Image11->Picture;
Image3->Picture=Image11->Picture;
Image4->Picture=Image11->Picture;
Image6->Picture=Image11->Picture;
Image7->Picture=Image11->Picture;
Image8->Picture=Image11->Picture;
Image9->Picture=Image11->Picture;
Image1->DragMode=dmAutomatic;
Image2->DragMode=dmAutomatic;
Image3->DragMode=dmAutomatic;
Image4->DragMode=dmAutomatic;
Image6->DragMode=dmAutomatic;
Image7->DragMode=dmAutomatic;
Image8->DragMode=dmAutomatic;
Image9->DragMode=dmAutomatic;
Image10->DragMode=dmAutomatic;
Image11->DragMode=dmAutomatic;
Image12->DragMode=dmAutomatic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image1->Tag=1;
Image1->Picture=Image10->Picture;
Image1->Enabled=false;
Image2->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image1->Tag=2;
Image1->Picture=Image12->Picture;
Image2->Enabled=false;
Image1->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1DragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept)
{
Accept=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image3DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image3->Tag=1;
Image3->Picture=Image10->Picture;
Image3->Enabled=false;
Image2->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image3->Tag=2;
Image3->Picture=Image12->Picture;
Image3->Enabled=false;
Image2->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image7DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image7->Tag=1;
Image7->Picture=Image10->Picture;
Image7->Enabled=false;
Image2->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image7->Tag=2;
Image7->Picture=Image12->Picture;
Image7->Enabled=false;
Image2->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image9DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image9->Tag=1;
Image9->Picture=Image10->Picture;
Image2->Enabled=false;
Image9->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image9->Tag=2;
Image9->Picture=Image12->Picture;
Image9->Enabled=false;
Image2->Enabled=false;
Image4->Enabled=false;
Image6->Enabled=false;
Image8->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image2DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image2->Tag=1;
Image2->Picture=Image10->Picture;
Image2->Enabled=false;
Image1->Enabled=false;
Image3->Enabled=false;
Image7->Enabled=false;
Image9->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image2->Tag=2;
Image2->Picture=Image12->Picture;
Image2->Enabled=false;
Image1->Enabled=false;
Image3->Enabled=false;
Image7->Enabled=false;
Image9->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image4DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image4->Tag=1;
Image4->Picture=Image10->Picture;
Image4->Enabled=false;
Image1->Enabled=false;
Image3->Enabled=false;
Image7->Enabled=false;
Image9->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image4->Tag=2;
Image4->Picture=Image12->Picture;
Image4->Enabled=false;
Image1->Enabled=false;
Image3->Enabled=false;
Image7->Enabled=false;
Image9->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image6DragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
if(Source==Image10 && a!=2)
{ Image6->Tag=1;
Image6->Picture=Image10->Picture;
Image6->Enabled=false;
Image1->Enabled=false;
Image3->Enabled=false;
Image7->Enabled=false;
Image9->Enabled=false; a++;
}
if(Source==Image12 && b!=2)
{ Image6->Tag=2;
Image6->Picture=Image12->Picture;
Image6->Enabled=false;
Image1->Enabled=false;
Image3->Enabled=false;
Image7->Enabled=false;
Image9->Enabled=false; b++;
}
if (a==2 && b==2)
BitBtn1->Enabled=true;
}
//---------------------------------------------------------------------------