نمايش پست تنها
قديمي ۰۸-۲۱-۱۳۸۸, ۰۷:۲۳ بعد از ظهر   #5 (لینک دائم)
Astaraki Female
Administrator
 
آواتار Astaraki
 
تاريخ عضويت: خرداد ۱۳۸۷
محل سكونت: تهران-کرج!
پست ها: 3,465
تشكرها: 754
16,337 تشكر در 3,127 پست
My Mood: Mehrabon
ارسال پيغام Yahoo به Astaraki
Question

كد:
unit HV;

interface
const
 Left=false;
 Right=true;

 Human=0;
 Vampire=1;

Type
 TPopulation=array[Human..Vampire] of byte;

 TRiverCondition=Record
  SidesPopulation:array[Left..Right] of TPopulation;
  BoatSide:Boolean;
 end;

var
 n:byte;
 FirstSide:boolean;

 function Transport(a:TRiverCondition):Boolean;
implementation


function IsValid(a:TRiverCondition):boolean;
begin
 Result:=(a.SidesPopulation[Left][Human]>0)and
         (a.SidesPopulation[Left][Vampire]>0)and
         (a.SidesPopulation[Right][Human]>0)and
         (a.SidesPopulation[Right][Vampire]>0)and

         (a.SidesPopulation[Left][Human]>=
          a.SidesPopulation[Left][Vampire]) and

         (a.SidesPopulation[Right][Human]>=
          a.SidesPopulation[Right][Vampire]);

end;

function Goal(a:TRiverCondition):boolean;
begin
 Result:=(a.SidesPopulation[FirstSide][Human]=0)and
         (a.SidesPopulation[FirstSide][Vampire]=0)and
         (a.SidesPopulation[not FirstSide][Human]=n)and
         (a.SidesPopulation[not FirstSide][Vampire]=n);
end;

procedure WriteCondition(a:TRiverCondition);
begin
 //display a in somewhere
end;

function Transport(a:TRiverCondition):Boolean;
var
 vv,hh:byte;
 ok:Boolean;
 b:TRiverCondition;
begin
 b.BoatSide:=not a.BoatSide;
 ok:=Goal(a);
 if IsValid(a) and not ok then
 for vv:=0 to 2 do
   for hh:=0  to 2 do
     if ((vv+hh)>0) and (not ok) then begin
       b.SidesPopulation[a.BoatSide][Human]:=a.SidesPopulation[a.BoatSide][Human]-hh;
       b.SidesPopulation[not a.BoatSide][Human]:=a.SidesPopulation[a.BoatSide][Human]+hh;
       b.SidesPopulation[a.BoatSide][Vampire]:=a.SidesPopulation[a.BoatSide][Vampire]-vv;
       b.SidesPopulation[not a.BoatSide][Vampire]:=a.SidesPopulation[a.BoatSide][Vampire]+vv;

       ok:=Transport(b);
     end;


 if ok then WriteCondition(a);
 Result:=ok;
end;

end.
Astaraki آفلاين است   پاسخ با نقل قول
از Astaraki تشكر كرده اند:
green_Dream (۱۱-۲۲-۱۳۸۸), keeper (۰۱-۱۷-۱۳۹۲), M.Mhoosh (۱۰-۱۳-۱۳۹۴), mogtabaa (۰۷-۲۰-۱۳۹۰), mr.sina (۰۵-۲۴-۱۳۹۰), sam1983 (۰۸-۲۴-۱۳۹۲), tooppi (۱۱-۷-۱۳۸۸), vahab60 (۰۷-۶-۱۳۹۲)