Reply
Creating a Sequence Combination Generator
Old 06-23-2008, 06:49 PM Creating a Sequence Combination Generator
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
In a game I play we have combo moves called super blows that consist of a certain number of attacks on the head, body or legs. Everyone's combinations are different, you have to find them out on your own, and no combination can contain a part of a previous combination... so I wanted to make something that would help me find possible combinations for my super blows at every level. For example, my level 1 super blow is body-head and my level 2 super blow is head-head-head, which means my level 3 combo can't be leg-body-head-leg because it contains my level 1 combo.

What I'm trying to do is create a generator in which I can input all of my previous combinations and have it display a list of possible new ones for the next super blow.

Anyone know how I could pull this off with PHP? Thanks in advance
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
When You Register, These Ads Go Away!
Old 06-23-2008, 06:51 PM Re: Creating a Sequence Combination Generator
wayfarer07's Avatar
$frontend->developer

Posts: 1,015
Name: Abel Mohler
Location: Asheville, North Carolina USA
Why PHP? PHP is for web development. Do you need an API that can be accessed over the internet?
__________________
Go FREELANCE <=|If a donkey eats a melon, it is still a donkey... |=> Hire Me
wayfarer07 is online now
Reply With Quote
View Public Profile
 
Old 06-23-2008, 07:16 PM Re: Creating a Sequence Combination Generator
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Yes, other people would be using it as well.
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Old 06-23-2008, 08:12 PM Re: Creating a Sequence Combination Generator
wayfarer07's Avatar
$frontend->developer

Posts: 1,015
Name: Abel Mohler
Location: Asheville, North Carolina USA
If you work out some of the logic, maybe we can help you with the syntax. What do you have so far?
__________________
Go FREELANCE <=|If a donkey eats a melon, it is still a donkey... |=> Hire Me
wayfarer07 is online now
Reply With Quote
View Public Profile
 
Old 06-23-2008, 11:43 PM Re: Creating a Sequence Combination Generator
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Right now all I have is a very basic script that uses a random function to display graphics of either a head shot, body shot, or leg shot for how ever many hits are in the combo... Like this: http://dreammare.net/combo.php
PHP Code:
<?php
// this function displays random text in a sentence

function randomCombo() {

$hits = array(
=> 'combo_up.gif',
=> 'combo_middle.gif',
=> 'combo_down.gif');

srand ((double) microtime() * 1000000);
$random_number rand(0,count($hits)-1);

$sb = ($hits[$random_number]);
return 
$sb;

}

?>

<html>
<head>
<style type="text/css">
body {
font-family: verdana;
font-size: 14px;
font-weight: bold;
}

table {
font-family: verdana;
font-size: 12px;
font-weight: bold;
}
</style>
</head>
<body>
<center>

<br>
Legend: Legacy of The Dragons Super-Blow Generator
<hr size="1" width="500px" color="black">

<table width="500px" cellspacing="5" cellpadding="2" border="0">
<tr><td>Level 1</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td>Level 2</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td>Level 3</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td>Level 4</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td>Level 5</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td>Level 6</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td>Level 7</td><td><img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>">&nbsp;<img src="<?php echo randomCombo();?>"></td></tr>
<tr><td colspan="2" align="right"><hr size="1" width="500px" color="black">
Designed by: Omerta</td></tr>
</table>


</center>
</body>
</html>
The problems with this are that it generates the same combinations multiple times, the page needs to be refreshed every time I have to try a new sequence, most of the sequences generated contain previous level combos, and since I made it and know how it works no one else can use it
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Old 06-24-2008, 12:19 AM Re: Creating a Sequence Combination Generator
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
Um, I ignored your code whose purpose I didn't understand anyway. According to your original post, I believe this will help you:

PHP Code:
<pre><?php
//Set up using the first letter of each word (since they are unique)
$body_parts = array('h','b','l');
//Change as you please
$used_combinations = array('bh','hhh');

//For outputting something other than the first letter.
$translations = array('h'=>'head','b'=>'body','l'=>'legs');

//Calculates the allowed combinations and returns an array.
//Return value is always an array
function allowed_combinations($level_number 2$used_combos) {
  
$allowed_combos = array();
  if (
$level_number 1) {
    
//Now, generate all possible combinations for this level
    //Recursion is necessary
    
$all_combos get_all_combos($level_number);
    
//Figure out which to keep and which to toss
    
foreach ($all_combos as $a_combo) {
      
//Assume allowed
      
$allowed true;
      foreach (
$used_combos as $a_used_combo) {
        if (
strpos($a_combo$a_used_combo) !== false) {
          
//Used combo found in possible combo, so disallow adding.
          
$allowed false;
        }
      }
      if (
$allowed) {
        
$allowed_combos[] = $a_combo;
      }
    }
  } 
//else $level_number < 2, so what is there to do?
  
return $allowed_combos;
}
//Recursive function to fetch all combos for a specific level.
function get_all_combos($level_number) {
  
//Need the pieces to play with
  
global $body_parts;

  
$current_combos = array();
  if (
$level_number == 1) {
    
//No more recursion, so end this!
    
return $body_parts;
  } else if (
$level_number 1) {
    
//Have recursion, so go a level down.
    
$inner_combos get_all_combos($level_number-1);

    
//Now that all the inner combos have been retrieved, loop through them
    //and prepend each possible part
    
foreach ($inner_combos as $a_combo) {
      foreach (
$body_parts as $a_part) {
        
$current_combos[] = $a_part.$a_combo;
      }
    }
  }
  return 
$current_combos;
}
//Test for level 3
$allowances allowed_combinations(3,$used_combinations);

//Translate to words.
foreach ($allowances as $a_combination) {
  echo 
$translations[$a_combination[0]].'-'.$translations[$a_combination[1]].'-'.$translations[$a_combination[2]]."\n";
}
?>
CAVEAT: I made this up really quickly with elementary testing. It may not be 100% accurate, though it appears to be. The rest is for you to do, but this will help you with the hardest part of this assignment: the logic.

CAVEAT: This uses a recursive function and multiple loops. It is calculationally expensive. Caching results will be an intelligent move on your part.

EDIT: As an example of calculations, the script above performed 110 iterations through loops and that's not much work, relatively speaking.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites

Last edited by JeremyMiller : 06-24-2008 at 12:22 AM.
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-24-2008, 11:19 AM Re: Creating a Sequence Combination Generator
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Thanks for the reply The purpose was basically just to visually aide me in trying new combos while testing them out on the trainer, as it's basically just multiple instances of a random image generator I found and fiddled with. I made it a couple of months ago right before I had my daughter and I hadn't touched PHP in years, so I never got around to putting more effort and such into it.

Regarding your code, it seems to EXACTLY what I was looking to do, logically as you said. I'm sure I can manage to tweak it to do the other things I need, such as being able to input the previous combos via an HTML form, versus having them included in the code, and being able to specify the number of hits needed for the generated combo (another needed hit is added per each level, i.e. 2 hits for the level 1 combo, 3 hits for the level 2 combo, 4 hits for the level 3 combo, etc.)

I thank you graciously for your insight, time and effort... I'll go see what I can accomplish with your ideas and post my progress

Last edited by SunBlind : 06-24-2008 at 12:05 PM.
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Old 06-26-2008, 03:23 PM Re: Creating a Sequence Combination Generator
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
http://dreammare.net/combos

Well, this is my semi-finished product. It works like a charm, does what it's supposed to do, now I'm just working on the visual aspects and a few extras. I've implemented a highlight function to mark which combos have been tested (it's extremely basic, and I wish I had a way to hide the combo completely, but this works for now.) I've also made text-only versions of all the pages for those who prefer it.

The only other thing I have left to do is format the results so that they appear in a 3 column, x amount of rows table to make the list a little more compact. Some people have told me they had 250-400+ possible combinations resulting in a minimum of 8 pages of combos to test. So anyways, any ideas on how I can accomplish this? I attempted a while loop but since my results are pulled from a foreach loop instead of a database (which I'm horrible with using and prefer not to) I don't know how to implement it.
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Reply     « Reply to Creating a Sequence Combination Generator
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.77898 seconds with 12 queries