Page 1 of 1
Math...
Posted: Wed May 12, 2010 10:16 am
by Goofan
Hi! I wasnt sure were to post this so i guess im just posting it.
I got a project which is to build a Textbased browser game...
Ive gotten to the attack systematics!...
If you got any idees around this just tell me. or any other idee
I got X units each got a specific health and dmg assigned to it.
I also got Y units which also got these properties! The problem im having is to make them all lose if one unit attack or if 20 units attack... As far as it goes (on my project now it goes: (a-a) (a-b) (a-c) (a-d) (a-e)) Meaning first attacking unit will be the A and it attacks the enemy from top to buttom... I want it to attack each of the units at the same time
X is "the user" Y is the "enemy"
Now this is just an exampel
[text]
X got a setup of:
Units -> Health -> Dmg
A ->15 -> 30
B ->20 -> 20
C ->25 -> 25
D ->35 -> 40
E ->30 -> 35
Y got a setup of:
Units -> Health -> Dmg
A ->5 -> 60
B ->10 -> 55
C ->15 -> 40
D ->25 -> 45
E ->20 -> 50
[/text]
Now what i´ve tried is this:
[text]
A ->15 -> 30
B ->20 -> 20
C ->25 -> 25
D ->35 -> 40
E ->30 -> 35
Total:
5 ->125->140
A ->5 -> 60
B ->10 -> 55
C ->15 -> 40
D ->25 -> 45
E ->20 -> 50
Total:
5 ->75->210
[/text]
Math:
I dont know how to make them all attack each other more then i can add all health and all dmg and split it against the units!
//Thanks in advance
//Thomas
Re: Math...
Posted: Wed May 12, 2010 10:48 am
by ColonelSandersLite
Just in pseudocode (not doing your homework for you

:
Code: Select all
victory condition = 0
while (victory condition == 0)
{
Foreach xunits
{
yunit health = yunit health - xunit attack
}
Foreach yunits
{
xunit health = xunit health - yunit attack
}
foreach xunits
{
if xunit health < 1 delete unit
}
foreach yunits
{
if yunit health < 1 delete unit
}
if count xunits < 1 victory condition = victory condition + 1
if count yunits < 1 victory condition = victory condition + 2
};
if victory condition == 1 xwins
if victory condition == 2 ywins
if victory condition == 3 tie
I think that's what you where getting at.
Basically, this is just an excercise in comparing arrays against eachother.
Re: Math...
Posted: Wed May 12, 2010 10:50 am
by Goofan
hmm cant say no to it but another question:
As ure count... i would like to calc the unit loss of each unit in X and the same in Y... =) Thanks!
Re: Math...
Posted: Wed May 12, 2010 10:54 am
by ColonelSandersLite
Code: Select all
victory condition = 0
while (victory condition == 0)
{
Foreach xunits
{
yunit health = yunit health - xunit attack
}
Foreach yunits
{
xunit health = xunit health - yunit attack
}
xunits lost = 0
foreach xunits
{
if xunit health < 1
{
delete unit
xunits lost = xunits lost + 1
}
}
yunits lost = 0
foreach yunits
{
if yunit health < 1
{
delete unit
yunits lost = yunits lost + 1
}
}
if count xunits < 1 victory condition = victory condition + 1
if count yunits < 1 victory condition = victory condition + 2
};
if victory condition == 1 xwins
if victory condition == 2 ywins
if victory condition == 3 tie
just added a couple of counters. simple.
edit: fixed a mistake
Re: Math...
Posted: Wed May 12, 2010 10:56 am
by Goofan
I think ure code erase all enemy unit if they lose and none of the winning users soldiers!...
I got 5 diffrent types of units... say:
sword spear mace axe and halberd
5-----10----5-----4--------1
they meat "another player" which got the same units but diffrent amounts.
sword spear mace axe and halberd
3-----1----14-----4--------10
each Sword unit does 5 in dmg so user 2´s swordmen do a total of 15 dmg and user 1´s swordmen does 25 dmg...
Each unit also got an amount of health Sword got 15 spear got 5 ...
how do you combine and make it count the losses of each unit type and whats left... =)
I like ure idee otherwise =)
Re: Math...
Posted: Wed May 12, 2010 10:57 am
by Goofan
ColonelSandersLite wrote:Code: Select all
victory condition = 0
while (victory condition == 0)
{
Foreach xunits
{
yunit health = yunit health - xunit attack
}
Foreach yunits
{
xunit health = xunit health - yunit attack
}
xunits lost = 0
foreach xunits
{
if xunit health < 1
{
delete unit
xunits lost = xunits lost + 1
}
}
yunits lost = 0
foreach yunits
{
if yunit health < 1
{
delete unit
yunits lost = yunits lost + 1
}
}
if count xunits < 1 victory condition = victory condition + 1
if count yunits < 1 victory condition = victory condition + 2
};
if victory condition == 1 xwins
if victory condition == 2 ywins
if victory condition == 3 tie
just added a couple of counters. simple.
edit: fixed a mistage
hehe not really what i meant. hope my other exampel clear it out... =)
Re: Math...
Posted: Wed May 12, 2010 11:04 am
by ColonelSandersLite
Goofan wrote:I think ure code erase all enemy unit if they lose and none of the winning users soldiers!...
Nope, nothing is deleted until everything has attacked in my example.
in effect
unit x1 attacks unit y1, unit y1 counterattacks
unit x2 attacks unit y2, unit y2 counterattacks
unit x3 attacks unit y3, unit y3 counterattacks
etc...
Any unit who has no health left is deleted only after all units have attacked
Past that, I'm just not sure what exactly you mean.
Re: Math...
Posted: Wed May 12, 2010 11:11 am
by Goofan
U mean nothing gets erased until the end? so that unit 1 can attack each and every unit until there is no units left and then next unit do the same (And the counter attacks) and at the end it delete those who dies and then there is a winner with "lower amount of units left"? is this what ure code does? never used foreach so far so =)
Re: Math...
Posted: Mon May 17, 2010 8:58 am
by Goofan
I think ive solved it! Please tell me what you think of the method... if you might find any bugs or difficulties with it.
Althought 1 problem remains
Solution:
Code: Select all
Defending Units = "Sword, Mace, Axe, Pike"
Attacking Units = "Sword, Mace, Axe, Pike, Catapult"
Attacking Units = 5
Defending Units = 4
TotDmg = 150
TotUnits = 5
150/5 = 30
unit: 1,2,3,4 -> Hp 10,5,15,20
Unit 1 -> 5*10 -> 50 - 30 = 20
Unit 2 -> 0*5 -> 0 - 30 = -30
Unit 3 -> 4*15 -> 60 - 30 = 30
Unit 4 -> 8*20 -> 160 - 30 = 130
1 = 20
2 = -30
3 = 30
4 = 130
x = Units died (X would then be 1 as only unit 2 died)
y = Add all those minus units. (Y would then be -30)
TotUnits = TotUnits - 1 (Would then be 3)
y = y/TotUnits ( Y would then be 10)
Units: 1,2,4 -> Hp 10,20,120
unit 1 -> 10/10 = 1
Unit 2 -> 20/15 = 1.33 (Remove the .33(Doable))
Unit 4 -> 120/20 = 6
Units: Remained: Start With: Lost:
1---->1--------->5-------->4
2---->0--------->0-------->0
3---->1--------->4-------->3
4---->6--------->8-------->2
if Attacking Units 1&2&3&4 = 0 {
Attacer won
Else
Attacker lost (which would be the result)
}
OBS! Catapult vs wall will still be an 1 vs 1 battle
Next Problem would be to make the wall defence go with the units as they battle.
If i add "Health" as bonus from the wall then it might get more after the battle then before the battle and if i "take that away so that there cant be any more units added" there is still the problem of defending units maybe not losing any units even if the attacker atttacks with a big arme (Defending unit got bigger) as the wall extra health adds up "more then the attacker dmg"
Someone able to solve my new problem?
//Thanks in advance
//Thomas