It is currently Thu Aug 16, 2018 2:41 am

All times are UTC + 9:30 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Prototype attackable range code
PostPosted: Mon Sep 10, 2007 6:28 am 
Offline
User avatar

Joined: Sun Apr 01, 2007 3:14 am
Posts: 2228
Location: DE
K, got it done. The hardest part was actually trying to find a way to test it. This code will generate a 2D boolean array containing that region we need for AI but which is very hard to define in a short sentence.

This is the function to create the 2D array (I put it in BattleScreen for testing purposes):
Code:
/** Creates a 2D boolean array containing all valid attack points in range.
  * @param attacker The unit hoping to attack.
  * @param attackee The unit being targeted.
  * return A 2D boolean array representing the map with the value true in all attack-possible points. */
public boolean[][] findAttackPoints(Unit attacker, Unit attackee){
   /** Used to find possible attack positions. */
   MoveTraverse mt = attacker.getMoveRange();
   /** All tiles from which the attackee can be hit, given the attacker's range. */
   boolean[][] canHitFrom = new boolean[m.getMaxCol()][m.getMaxRow()];

   // First, set all locations to which the attacker can move next turn.
   canHitFrom = mt.getMoves();

   // Now step through the map and unset any locations from which the target cannot be hit.
   for(int i=0; i < m.getMaxCol(); i++){
      for(int j = 0; j < m.getMaxRow(); j++) {
         if(!attackee.checkOtherFireRange(attacker, new Location(i,j)))
            canHitFrom[i][j] = false;
      }
   }

   return canHitFrom;
}


This is a helper function that goes in Unit.java.
Code:
/** Checks if this unit could fire on a given square, assuming it had a specific attack range.
  * @param other A unit with the attack range to check.
  * @param l The location to check.
  * @return Whether or not the tile is in the range. */
public boolean checkOtherFireRange(Unit other, Location l){
   /** The absolute seperation between the unit and the location. */
   int t = Math.abs(l.getRow() - loc.getRow()) + Math.abs(l.getCol() - loc.getCol());

   if(t >= other.minRange && t <= other.getMaxRange())
      return true;
   return false;
}

_________________
urusan wrote:
Do what Fugue said


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 7:06 am 
Offline
User avatar

Joined: Sat Jun 24, 2006 3:11 pm
Posts: 1266
Location: Should be programming AI and Sound
Fugue. This code... is sexier than sex!

Thanks! <3

_________________
Image
Thanks to Taboo for the sig and avy. CLIFF NEEDS RATES AND COMMENTS: http://forums.customwars.com/viewtopic.php?t=5351


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 7:06 am 
Offline
User avatar

Joined: Mon Jan 01, 2007 12:13 pm
Posts: 1467
Location: México!
Translation for all of us non-programmers plz?

_________________
Image
Creds to Shinko. Creds to x0 for the avatar.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 7:35 am 
Offline

Joined: Thu Aug 30, 2007 2:32 pm
Posts: 1575
Helps AI-controlled units find a route to attack enemy units, rather than move mindlessly towards the enemy HQ and hope something's in range. Just guessing.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 7:47 am 
Offline
User avatar

Joined: Sun Apr 01, 2007 3:14 am
Posts: 2228
Location: DE
Dunno how it chalks up to sex, but thanks and no problem.

It's code to solve the following problem, which is an important starting point for AI:
Image
This code will let the AI find the dark red squares.

_________________
urusan wrote:
Do what Fugue said


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 5:46 am 
Offline

Joined: Sun Dec 24, 2006 1:59 am
Posts: 179
Ah. Looks like my illustrated method have been used.
Madness? THIS. IS. OBVIOUSNESS!

But are more illustrated methods necessary? Because I'm not really good at managing my time which makes me unable to do more of those stuff.

Anyway, it's nice to see that I didn't do this for nothing. And it'll be even nicer when we all will be able to see this used by the AI.
And sorry if I don't really look unthusiastic and thankful, I don't have enough vocabulary for this.

...

Or maybe it's just lazyness. But don't blame me, I could have used nubsp33k.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 9:30 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Blue Moon by Trent © 2007
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group