Autor Beitrag
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 07.12.02 19:55 
Hallo,
ich habe bei meiner ki in PacMan ein problem hier erstmal der code:
Code:

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
for i:=0 to 9 do begin 
  //  game.ki[i].is_links:=False; game.ki[i].is_rechts:=false; 
//    game.ki[i].is_oben:=False;  game.ki[i].is_unten:=False; 
    
    inc(Game.Ki[i].tick); 
    if Game.Ki[i].tick = Game.Ki[i].tickcount then begin 
      Game.Ki[i].Gehe:=True; 
      Game.Ki[i].tick:=0 
    end; 

    if Game.ki[i].Gehe = True then begin 
      if Game.Karte[Game.ki[i].x,Game.ki[i].y].typ = _monster then 
        Game.Karte[Game.ki[i].x,Game.ki[i].y].Typ:=Game.ki[i].oldTex; 

      if (Game.Karte[Game.KI[i].x,Game.KI[i].y-1 ].typ <> _wand) and (Game.Karte[Game.KI[i].x,Game.KI[i].y-1].typ <> _monster)  then begin 
        game.ki[i].is_unten:=True; 
      end 
      else begin 
        game.ki[i].is_unten:=False; 
        Game.ki[i].dir:=_none; 
      end; 

      if (Game.Karte[Game.KI[i].x, Game.KI[i].y+1 ].typ <> _wand) and (Game.Karte[Game.KI[i].x,Game.KI[i].y+1].typ <> _monster) then begin 
        game.ki[i].is_oben:=True; 
      end 
      else begin 
        Game.ki[i].dir:=_none; 
        game.ki[i].is_oben:=False; 
      end; 

      if (Game.Karte[Game.KI[i].x-1,Game.KI[i].y ].typ <> _wand) and (Game.Karte[Game.KI[i].x-1,Game.KI[i].y].typ <> _monster) then begin 
        game.ki[i].is_links:=True 
      end 
      else begin 
        Game.ki[i].dir:=_none; 
        game.ki[i].is_links:=False; 
      end; 

      if (Game.Karte[Game.KI[i].x+1, Game.KI[i].y ].typ <> _wand) and (Game.Karte[Game.KI[i].x+1,Game.KI[i].y].typ <> _monster) then begin 
        game.ki[i].is_rechts:=True; 
      end 
      else begin 
        Game.ki[i].dir:=_none; 
        game.ki[i].is_rechts:=False; 
      end;          

      if (game.ki[i].is_links = False) and (game.ki[i].is_rechts = False) and (game.ki[i].is_unten = False) and (game.ki[i].is_oben = True) then 
        Game.ki[i].dir:=_oben; 

      if (game.ki[i].is_links = True) and (game.ki[i].is_rechts = True) and (game.ki[i].is_unten = False) and (game.ki[i].is_oben = True) then 
        Game.ki[i].dir:=_oben; 


      if (game.ki[i].is_links = True) and (game.ki[i].is_rechts = True) and (game.ki[i].is_unten = True) and (game.ki[i].is_oben = True) then 
        Game.ki[i].dir:=random(3); 

      Game.Ki[i].x:=Game.Ki[i].x + Game.dirs[Game.Ki[i].dir].x; 
      Game.Ki[i].y:=Game.Ki[i].y + Game.dirs[Game.Ki[i].dir].y; 
      
      Game.ki[i].oldTex:=Game.Karte[Game.ki[i].x,Game.ki[i].y].Typ; 
      Game.Karte[Game.ki[i].x,Game.ki[i].y].Typ:=_monster; 
      Game.ki[i].Gehe:=False; 
    end; 

    DXImageList1.Items[_monster].Draw( DXDraw1.Surface, Game.Ki[i].x*_MapS , Game.Ki[i].y*_MapS, 0 ); 
  end;

das problem ist einfach das sich die ki nicht über den bildschirm verteielt
wie bekomme ich das hin ???
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Sa 07.12.02 20:05 
Habe den code mal überflogen und glaube, ich weiß, wo das Problem liegt: wenn das Monster auf ein Hindernis stößt, geht es in eine zufällige Richtung. Wenn du immer nach Zufall handelst, wird es sich irgendiwe unkoordiniert im kreis bewegen. Du solltest eine richtung "bevorzugen". Mach' zum Record-Typ eine Vorzugsrichtung hinzu, nachder dein Monster läuft. Wenn es an ein Hindernis gerät, läuft es z.B. mit 85%iger Wahrscheinlichkeit in die vorzugsrichtung. Dann kannst du noch anweisen, dass sich die vorzugsrichtung mit 10%iger Wahrscheinlichkeit ändert.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 07.12.02 20:06 
und wie ?
kannst du mir mal ein kleines beispiel für die ki machne ?
das ist nämlich das erstemal das ich eine KI für ein Spiel schreibe !
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 07.12.02 21:01 
so nun habe ich denn code wieder so wie ich ihn vohrer geschriben hatte:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
for i:=0 to 9 do begin

    inc(Game.Ki[i].tick);
    if Game.Ki[i].tick = Game.Ki[i].tickcount then begin
      Game.Ki[i].Gehe:=True;
      Game.Ki[i].tick:=0
    end;

    if Game.ki[i].Gehe = True then begin
      x:=Game.ki[i].x; y:=Game.ki[i].y;

      if (Game.Karte[x,y+1].Typ <> _Monster) and (Game.Karte[x,y+1].Typ <> _Wand) and (Game.ki[i].dir = _None) then begin
        Game.ki[i].dir:=_oben;
        Game.Karte[x,y].Typ:=_None;
        Inc(y);
        Game.Karte[x,y].Typ:=_monster;
        Game.ki[i].y:=y;
        Game.ki[i].Gehe:=False;
      end
      else
        Game.ki[i].dir:=_none;

      if (Game.Karte[x,y-1].Typ <> _Monster) and (Game.Karte[x,y-1].Typ <> _Wand) and (Game.ki[i].dir = _None)then begin
        Game.ki[i].dir:=_unten;
        Game.Karte[x,y].Typ:=_None;
        dec(y);
        Game.Karte[x,y].Typ:=_monster;
        Game.ki[i].y:=y;
        Game.ki[i].Gehe:=False;
      end
      else
        Game.ki[i].dir:=_None;


      if (Game.Karte[x-1,y].Typ <> _Monster) and (Game.Karte[x-1,y].Typ <> _Wand) and (Game.ki[i].dir = _None)then begin
        Game.ki[i].dir:=_links;
        Game.Karte[x,y].Typ:=_None;
        dec(x);
        Game.Karte[x,y].Typ:=_monster;
        Game.ki[i].x:=x;
        Game.ki[i].Gehe:=False;
      end
      else
        Game.ki[i].dir:=_None;

      if (Game.Karte[x+1,y].Typ <> _Monster) and (Game.Karte[x+1,y].Typ <> _Wand) and (Game.ki[i].dir = _None)then begin
        Game.ki[i].dir:=_links;
        Game.Karte[x,y].Typ:=_None;
        inc(x);
        Game.Karte[x,y].Typ:=_monster;
        Game.ki[i].x:=x;
        Game.ki[i].Gehe:=False;
      end
      else
        Game.ki[i].dir:=_None;

    end;

    DXImageList1.Items[_monster].Draw( DXDraw1.Surface, Game.ki[i].x*_MapS , Game.ki[i].y*_MapS, 0 );
  end;


aber dieser code enhält auch noch mägel z.B
die ki läuft immmer gleich alle laufen immer hintereinen her.
kann mir jemmand sagen was ich besser machen muss ?

MFG
mimi
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 07.12.02 21:16 
Wie bekomme ich das hin das sie sich kreiß förmig ausbreiten ?
und zwar sich schnell ausbreiten ?

MFG
mimi