Message Boards Message Boards

GAME: Medieval Combat Simulator

Index:

  • Description

  • Code

  • Details:

-Units/Quantity

-Units/Armor

-Units/Experience

-Units/Modifiers

-Terrains

-Catastrophe

-Sounds/Music

-Combat Results

Description:

This is a medieval combat simulator with code-based in the Wolfram Language, where there are two teams that battle each other with their basic combat units, each with their combat value, which can have various types of armor, combat experience and modifiers. There are also some types of terrain each with their modifiers and also modify the behavior of the units in combat. There is a catastrophe option that can be disabled or enabled and has a chance to occur, also can be changed. The game has sound effects when there is an evaluation (one for normal evaluate and the other for event of catastrophe) and two types of songs that alternatively can be selected. Each result is unique and takes into account all the previous factors described. The result is numerical and graphic and also estimates the winning team and the number of surviving units at the end of the fight.

Code:

The complete code of the game is the following (the details of the game comes described after the same):

(*"quantity of units/team(1&2)","armor","experience",
"terrain","catastrophe","sound/music"*)
(*{no armor=>0,leather armor=>1,rings armor=>2,
plate armor=>3}*)
(*{experience/teams:"no experience"=>0 to "very experienced"=>10}*)
(*{terrain:clean=>0,obstacles=>1,severe=>2*)
(*{possibility of catastrophe:off=>{0},on=>{1}};
{chance:"0%"=>0 to "100%"=>10}*)
(*{sounds/music:off=>{0},on=>{1}}*)

(*..............................input...............................*)


{};
a = brassgladius1 = 0; armor1a = 0;
b = irongladius1 = 100; armor2a = 1;
c = brasslongswordman1 = 0; armor3a = 0;
d = lightmaceman1 = 0; armor4a = 0;
e = axeman1 = 0; armor5a = 0;
f = spearman1 = 0; armor6a = 0;
g = heavymaceman1 = 50; armor7a = 2;
h = ironlongswordman1 = 50; armor8a = 3;
i = ranger1 = 0; armor9a = 0;
j = trebuchet1 = 0;
k = northman1 = 0; armor11a = 0;
l = knight1 = 0; armor12a = 0;
warbeasts1 = 10;
xp1 = teamexperience1 = 2;
gg1 = terrain1 = 0;

m = brassgladius2 = 0; armor1b = 0;
n = irongladius2 = 100; armor2b = 1;
o = brasslongswordman2 = 0; armor3b = 0;
p = lightmaceman2 = 0; armor4b = 0;
q = axeman2 = 0; armor5b = 0;
r = spearman2 = 0; armor6b = 0;
s = heavymaceman2 = 50; armor7b = 2;
t = ironlongswordman2 = 50; armor8b = 3;
u = ranger2 = 0; armor9b = 0;
v = trebuchet2 = 0;
w = northman2 = 0; armor11b = 0;
x = knight2 = 0; armor12b = 0;
warbeasts2 = 10;
xp2 = teamexperience2 = 2;
gg2 = terrain2 = 0;

catastrophe = {1}; chance = 2;

evalsound = {1};
music1 = {0};
music2 = {0};

(*.................................code............................*)


da = (0.18); h1 = 0.03; h2 = 0.15;
armor10a = 0;
armor10b = 0;
? = 1.0; ? = 1.0; ? = (armor1a + 1)^da; ? = (armor1b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 1.2; ? = 1.2; ? = (armor2a + 1)^da; ? = (armor2b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 1.4; ? = 1.4; ? = (armor3a + 1)^da; ? = (armor3b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 1.6; ? = 1.6; ? = (armor4a + 1)^da; ? = (armor4b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 1.8; ? = 1.8; ? = (armor5a + 1)^da; ? = (armor5b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 2.2; ? = 2.2; ? = (armor6a + 1)^da; ? = (armor6b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 2.4; ? = 2.4; ? = (armor7a + 1)^da; ? = (armor7b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 2.6; ? = 2.6; ? = (armor8a + 1)^da; ? = (armor8b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 2.4; ? = 2.4; ? = (armor9a + 1)^da; ? = (armor9b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 7.0; ? = 7.0; ? = (armor10a + 1)^da; ? = (armor10b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 2.4; ? = 2.4; ? = (armor11a + 1)^da; ? = (armor11b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 3.0; ? = 3.0; ? = (armor12a + 1)^da; ? = (armor12b + 1)^da; ? = 
 ?*(1 + RandomReal[{h1*xp1, h2*xp1}]); ? = 
 ?*(1 + RandomReal[{h1*xp2, h2*xp2}]);
? = 9.0; ? = 9.0;
y1 = Flatten[
   Table[Table[
      If[(ll1 == 10 \[And] gg1 == 2) \[Or] (ll1 == 11 \[And] 
           gg1 == 2) \[Or] (ll1 == 12 \[And] gg1 == 2), 
        If[ll1 == 10, -6.0, If[ll1 == 11, 1.5, -1.5]], 0] + 
       If[(ll1 == 6 \[And] gg1 == 1) \[Or] (ll1 == 9 \[And] 
           gg1 == 1) \[Or] (ll1 == 10 \[And] gg1 == 1), 
        If[ll1 == 6, -1.0, If[ll1 == 10, -5.0, 1.5]], 0] + 
       If[(ll1 == 6 \[And] gg1 == 0) \[Or] (ll1 == 12 \[And] 
           gg1 == 0), 0.5, 
        0] + (FromCharacterCode[4095 + ll1] // 
         ToExpression), {FromCharacterCode[96 + ll1] // 
        ToExpression}], {ll1, 1, 12}]*
    Table[Table[
      FromCharacterCode[4124 + lll1] // 
       ToExpression, {FromCharacterCode[96 + lll1] // 
        ToExpression}], {lll1, 1, 12}]];
y1x = Flatten[
   Table[Table[
      If[(ll1 == 10 \[And] gg1 == 2) \[Or] (ll1 == 11 \[And] 
           gg1 == 2) \[Or] (ll1 == 12 \[And] gg1 == 2), 
        If[ll1 == 10, -6.0, If[ll1 == 11, 1.5, -1.5]], 0] + 
       If[(ll1 == 6 \[And] gg1 == 1) \[Or] (ll1 == 9 \[And] 
           gg1 == 1) \[Or] (ll1 == 10 \[And] gg1 == 1), 
        If[ll1 == 6, -1.0, If[ll1 == 10, -5.0, 1.5]], 0] + 
       If[(ll1 == 6 \[And] gg1 == 0) \[Or] (ll1 == 12 \[And] 
           gg1 == 0), 0.5, 
        0] + (FromCharacterCode[4192 + ll1] // 
         ToExpression), {FromCharacterCode[96 + ll1] // 
        ToExpression}], {ll1, 1, 12}]*
    Table[Table[
      FromCharacterCode[4124 + lll1] // 
       ToExpression, {FromCharacterCode[96 + lll1] // 
        ToExpression}], {lll1, 1, 12}]];
y3 = Flatten[
   Table[FromCharacterCode[4149] // ToExpression, {warbeasts1}]];
hj = Join[Table[0, 10 - chance], Table[1, chance]];
catx = RandomChoice[hj];
If[FromDigits[catastrophe] == 1, 
  If[catx == 1, cat1 = RandomReal[{0.05, 0.8}], cat1 = 1], cat1 = 1];
If[FromDigits[catastrophe] == 1, 
  If[catx == 1, cat2 = RandomReal[{0.05, 0.8}], cat2 = 1], cat2 = 1];
yy1 = cat1*(y1 + 
     Table[RandomReal[{-0.67, 0.67}]*
       FromDigits[Take[y1x*(1 - 0.1*gg1), {bx1}]], {bx1, 1, 
       Count[y1, _]}] - (gg1*0.33)*y1x*
      Table[N[Abs[Cos[RandomInteger[{10, 200}]]/3], 10], {bx1, 1, 
        Count[y1, _]}]);
yy3 = cat1*(y3 + 
     Table[RandomReal[{-0.33, 0.33}]*
       FromDigits[Take[y3*(1 - 0.1*gg1), {bxx1}]], {bxx1, 1, 
       Count[y3, _]}] - (gg1*1.0)*y3*
      Table[N[Abs[Cos[RandomInteger[{10, 200}]]/3], 10], {bxx1, 1, 
        Count[y3, _]}]);
z1 = Flatten[
   Table[Take[FromDigits[Take[Tally[y1x], {ii1}]], {1}], {ii1, 1, 
     Count[Tally[y1x], _]}]];
zz1 = Sum[
    NIntegrate[
     FromDigits[Take[z1, {bb1}]], {aa1, 0, 
      Count[y1x, FromDigits[Take[z1, {bb1}]]]}], {bb1, 1, 
     Count[z1, _]}] + 
   Count[y3, _]*(FromCharacterCode[4149] // ToExpression);
y2 = Flatten[
   Table[Table[
      If[(ll2 == 10 \[And] gg2 == 2) \[Or] (ll2 == 11 \[And] 
           gg2 == 2) \[Or] (ll2 == 12 \[And] gg2 == 2), 
        If[ll2 == 10, -6.0, If[ll2 == 11, 1.5, -1.5]], 0] + 
       If[(ll2 == 6 \[And] gg2 == 1) \[Or] (ll2 == 9 \[And] 
           gg2 == 1) \[Or] (ll2 == 10 \[And] gg2 == 1), 
        If[ll2 == 6, -1.0, If[ll2 == 10, -5.0, 1.5]], 0] + 
       If[(ll2 == 6 \[And] gg2 == 0) \[Or] (ll2 == 12 \[And] 
           gg2 == 0), 0.5, 
        0] + (FromCharacterCode[4107 + ll2] // 
         ToExpression), {FromCharacterCode[108 + ll2] // 
        ToExpression}], {ll2, 1, 12}]*
    Table[Table[
      FromCharacterCode[4136 + lll2] // 
       ToExpression, {FromCharacterCode[108 + lll2] // 
        ToExpression}], {lll2, 1, 12}]];
y2x = Flatten[
   Table[Table[
      If[(ll2 == 10 \[And] gg2 == 2) \[Or] (ll2 == 11 \[And] 
           gg2 == 2) \[Or] (ll2 == 12 \[And] gg2 == 2), 
        If[ll2 == 10, -6.5, If[ll2 == 11, 1.5, -1.5]], 0] + 
       If[(ll2 == 6 \[And] gg2 == 1) \[Or] (ll2 == 9 \[And] 
           gg2 == 1) \[Or] (ll2 == 10 \[And] gg2 == 1), 
        If[ll2 == 6, -1.0, If[ll2 == 10, -6.0, 1.5]], 0] + 
       If[(ll2 == 6 \[And] gg2 == 0) \[Or] (ll2 == 12 \[And] 
           gg2 == 0), 0.5, 
        0] + (FromCharacterCode[4204 + ll2] // 
         ToExpression), {FromCharacterCode[108 + ll2] // 
        ToExpression}], {ll2, 1, 12}]*
    Table[Table[
      FromCharacterCode[4136 + lll2] // 
       ToExpression, {FromCharacterCode[108 + lll2] // 
        ToExpression}], {lll2, 1, 12}]];
y4 = Flatten[
   Table[FromCharacterCode[4150] // ToExpression, {warbeasts2}]];
yy2 = cat2*(y2 + 
     Table[RandomReal[{-0.67, 0.67}]*
       FromDigits[Take[y2x*(1 - 0.1*gg2), {bx2}]], {bx2, 1, 
       Count[y2, _]}] - (gg2*0.33)*y2x*
      Table[N[Abs[Cos[RandomInteger[{10, 200}]]/3], 10], {bx2, 1, 
        Count[y2, _]}]);
yy4 = cat2*(y4 + 
     Table[RandomReal[{-0.33, 0.33}]*
       FromDigits[Take[y4*(1 - 0.1*gg2), {bxx2}]], {bxx2, 1, 
       Count[y4, _]}] - (gg2*1.0)*y4*
      Table[N[Abs[Cos[RandomInteger[{10, 200}]]/3], 10], {bxx2, 1, 
        Count[y4, _]}]);
z2 = Flatten[
   Table[Take[FromDigits[Take[Tally[y2x], {ii2}]], {1}], {ii2, 1, 
     Count[Tally[y2x], _]}]];
zz2 = -Sum[
     NIntegrate[
      FromDigits[Take[z2, {bb2}]], {aa2, 0, 
       Count[y2x, FromDigits[Take[z2, {bb2}]]]}], {bb2, 1, 
      Count[z2, _]}] - 
   Count[y4, _]*(FromCharacterCode[4150] // ToExpression);
ccd = FromDigits[
   Take[Sort[{Count[yy1, _], Count[yy2, _], Count[yy3, _], 
      Count[yy4, _]}], {4}]];
m1 = If[ccd > Count[yy1, _], 
   Join[yy1, Table[0, {ccd - Count[yy1, _] + 2}]], Join[yy1, {0, 0}]];
m2 = If[ccd > Count[yy2, _], 
   Join[yy2, Table[0, {ccd - Count[yy2, _] + 2}]], Join[yy2, {0, 0}]];
m3 = If[ccd > Count[yy3, _], 
   Join[yy3, Table[0, {ccd - Count[yy3, _] + 2}]], 
   Join[yy3, 
    If[Count[y3, _] > Count[y1, _], 
     If[Count[y1, _] == 0, {0, 0}, {0}], {0, 0}]]];
m4 = If[ccd > Count[yy4, _], 
   Join[yy4, Table[0, {ccd - Count[yy4, _] + 2}]], 
   Join[yy4, 
    If[Count[y4, _] > Count[y2, _], 
     If[Count[y2, _] == 0, {0, 0}, {0}], {0, 0}]]];
f1 = If[y1 != {}, 
   ListInterpolation[m1, Method -> "Hermite", 
    InterpolationOrder -> 1 + If[gg1 == 2, (-1), gg1]], 0];
f2 = If[y2 != {}, 
   ListInterpolation[(-1)*m2, Method -> "Hermite", 
    InterpolationOrder -> 1 + If[gg2 == 2, (-1), gg2]], 0];
f3 = If[y3 != {}, 
   ListInterpolation[m3, Method -> "Hermite", 
    InterpolationOrder -> 2 + If[gg1 == 2, (-1), -2*gg1]], 0];
f4 = If[y4 != {}, 
   ListInterpolation[(-1)*m4, Method -> "Hermite", 
    InterpolationOrder -> 2 + If[gg2 == 2, (-1), -2*gg2]], 0];
If[FromDigits[evalsound] == 1, 
 If[catx == 1 \[And] FromDigits[catastrophe] == 1, 
  EmitSound[
   Sound[{SoundNote["C", 0.2, "VoiceAahs", SoundVolume -> 1/2], 
     SoundNote["A", 0.2, "VoiceAahs", SoundVolume -> 1/2], 
     SoundNote["E", 0.2, "VoiceAahs", SoundVolume -> 1/2], 
     SoundNote["D", 0.2, "VoiceAahs", SoundVolume -> 1/2]}]], 
  EmitSound[
   Sound[{SoundNote["C", 0.13, SoundVolume -> 1/2], 
     SoundNote["A", 0.13, SoundVolume -> 1/2], 
     SoundNote["E", 0.13, SoundVolume -> 1/2]}]]], Null]
If[FromDigits[music1] == 1, 
 Sound[Table[
   SoundNote[RandomInteger[{-5, 15}], RandomReal[{0.5, 1.2}], 
    "Violin", SoundVolume -> 1/2], 380]], Null]
If[FromDigits[music2] == 1, 
 Sound[Table[
   SoundNote[RandomInteger[{-20, 50}], RandomReal[{0.35, 0.65}], 
    RandomChoice[{"Crystal", "Woodblock", "Whistle", "VoiceAahs", 
      "Woodblock"}], SoundVolume -> 1/2], 600]], Null]
Plot[{f1[xx], f2[xx], f3[xx], f4[xx]}, {xx, 1, 
  FromDigits[
   Take[Sort[{Count[m1, _], Count[m2, _], Count[m3, _], 
      Count[m4, _]}], {4}]]}, 
 PlotRange -> {{1, Automatic}, {-11, 11}}, 
 Filling -> {1 -> {0, Directive[Opacity[0.6], Blue]}, 
   2 -> {0, Directive[Opacity[0.9], Black]}, 
   3 -> {0, Directive[Opacity[0.5], Green]}, 
   4 -> {0, Directive[Opacity[0.25], Green]}}, 
 PlotStyle -> {Directive[Blue, Bold], Directive[Orange], 
   Directive[Red, Thin], Directive[Purple, Thin]}, 
 AxesStyle -> {Directive[{Thick, White, Dashed, Bold}], 
   Directive[{Thick, Red, Dashed, Bold}]}, ImageSize -> Large, 
 PlotLegends -> {"Team1", "Team2", "WarBeasts1", "WarBeasts2"}]
sor = Sort[{Count[m1, _], Count[m2, _], Count[m3, _], Count[m4, _]}, 
   Greater];
ff1 = If[y1 != {}, 
   NIntegrate[f1[xx], {xx, 1, FromDigits[Take[sor, {1}]]}], 0];
ff2 = If[y2 != {}, 
   NIntegrate[f2[xx], {xx, 1, FromDigits[Take[sor, {1}]]}], 0];
ff3 = If[y3 != {}, 
   NIntegrate[f3[xx], {xx, 1, FromDigits[Take[sor, {1}]]}], 0];
ff4 = If[y4 != {}, 
   NIntegrate[f4[xx], {xx, 1, FromDigits[Take[sor, {1}]]}], 0];
{{Count[y1, _] + Count[y3, _], 
  zz1, (ff1 + ff3)}, {Count[y2, _] + Count[y4, _], zz2, (ff2 + ff4)}}
me3 = N[(Total[yy1] + Total[yy3])/(Count[yy1, _] + Count[yy3, _])];
ne3 = N[(-1)*(Total[yy2] + Total[yy4])/(Count[yy2, _] + 
       Count[yy4, _])];
kk3 = If[(ff1 + ff2 + ff3 + ff4) > 0, 
   IntegerPart[(ff1 + ff2 + ff3 + ff4)/me3] + 1, 
   IntegerPart[(ff1 + ff2 + ff3 + ff4)/ne3] + 1];
kkp = If[(ff1 + ff2 + ff3 + ff4) > 0, 
   N[100*(IntegerPart[(ff1 + ff2 + ff3 + ff4)/me3] + 
        1)/(Count[yy1, _] + Count[yy3, _]), 3], 
   N[100*(IntegerPart[(ff1 + ff2 + ff3 + ff4)/ne3] + 
        1)/(Count[yy2, _] + Count[yy4, _])], 3];
{kk3, {kkp}}
If[FromDigits[catastrophe] == 1 \[And] catx == 1, 
 If[cat1 > 0.4 \[And] cat2 > 0.4, 
  Style["TORNADO!?", FontSize -> Large, Cyan, Bold], 
  If[0.4 > cat1 > 0.15 \[Or] 0.4 > cat2 > 0.15, 
   Style["EARTHQUAKE!?", FontSize -> Large, Brown, Bold], 
   Style["VOLCANO!?", FontSize -> Large, Red, Bold]]], Null]
If[ff1 + ff2 + ff3 + ff4 > 0, 
 Style["TEAM\[Rule]1 WINS \[BlackKing]?", FontSize -> Large, Blue, 
  Bold], Style["TEAM\[Rule]2 WINS \[WhiteKing]?", FontSize -> Large, 
  Orange, Bold]]
{Style["thanks to", Small, Purple], 
 Style["\[WolframLanguageLogo]", Large, Bold, Purple]}

Simpler examples of results (also explained below):

image1

image1b

Details:

  • Units/Quantity:

There are 12 types of combat units plus 1 type of combat creature (warbeasts) on each team. The quantities of each type can be selected separately by type and by team. The game supports (with precision) from 0 to 999 total units in each team plus a value from 0 to 999 of beasts. In total, each team can have a maximum of 999 basic units and 999 beasts simultaneously, but can be done the evaluation of 1 creature or 1 unit on each team if desired. Teams can have very different quantities of units and creatures to each other in each fight if you want, for example, a team with 200 units and the other with only 80 units.

  • Units/Armor:

In the game there are 4 options for armor, 0 is without armor, 1 is leather armor, 2 is armor rings and 3 is armor of metal plates. Each unit type can have its armor selected separately (except the beasts and trebuchet) for each team and give combatants different bonuses in combat values.

  • Units/Experience:

You can select experience values for the units (this does not apply to beasts) per team as a whole, with values from 0 (no experience) up to 10 (very experienced). Experience also affects combat values and symbolizes the difference between new units or veteran units.

  • Units/Modifiers:

The modifiers of each unit are dependent on each type of terrain where the team in question is located. For example, trebuchet is powerful in clean terrain while little efficient on terrain of obstacles (forest). The ranger is much more powerful on terrain with obstacles than in clean terrain. And other units also have this dependence on terrain, such as the spearman, knight, northman (better on severe terrain), etc...

  • Terrains:

The terrain besides affecting the modifiers of the units also affect the behavior of the units. There are 3 types of land: clean, with obstacles and severe. The behavior works as follows: In the clean terrain the units help themselves in grade 1 (linear-middle) while the beasts in grade 2 (curve-better). In the terrain with obstacles the units help in grade 2 (curve) because there is more caution, while the beasts do not help each other and stand each on their own-grade 0 (constant-worse). In the severe terrain the units are unable to help themselves – grade 0 (constant) while the creatures help themselves in a basic way – grade 1 (linear). The terrain can be chosen independently for each team.

  • Catastrophe:

The option of catastrophe can be disabled and freely enabled, as well as its frequency: 0 to 0% chance up to 10 to 100% chance of occurrence. Catastrophe can significantly affect the progress of combat, causing massive damage randomly on each team. There are 3 types of catastrophe according to the damage dealt in the game: tornado (moderate), earthquake (major damage) and volcano (deadly), and appear randomly and automatically with the indication of occurrence in the result.

image2

Example of volcano catastrophe event:

image2b

  • Sounds/Music:

At each evaluate there is a specific sound for normal results and a specific sound in case there is catastrophe. The sound in the game can be disabled and enabled freely. Alternatively there are 2 types of songs that can be enabled and played during the game, music 1 is more classic (violin) while music 2 is more exotic (some exotic instruments/vocals). To turn on the songs just press the play button after the combat evaluate and to turn off just press the stop button. The sounds of the game overlap the music, so to keep the music playing it is necessary to disable the sounds of the game.

  • Combat Results:

The result of the match is both numerical and chart. In the graph, team 1 is at the top and team 2 is at the bottom. The result shows the total number of units of each team, the total (theoretical) combat value of each team and the effective values for each evaluate generated with the experience modifiers and random factors ("+" for team 1 and "–" for team 2). The result also tells which team won and the estimated number of surviving units in the winning team as well as their % in relation to the team total.

image3

This work is my version (v. 1.1) of medieval combat with a simple code (raw interface), which I developed using Mathematica.

Thank you very much to everyone in the community!

POSTED BY: Claudio Chaib

Extra Songs:

To add extra songs in the game just put this simple code in the input part (in this case a song 3): add a line: music3={0};

imag4

Just switch {0} to {1} to activate the new song. And of course add a code to the song as follows (example):

imag5

Just replace "music3" with the music code, this can be done on the line where the other songs are in the code or even at the end of the game code. It works the same.

  • music3 example (more elaborate song):

Below is the code of a song a little more elaborate to be the music3, where there are several instruments (4 – guitar, panflute, bass, synthdrum) with a musical base, the main instrument is still random but more harmonized with the sound in general:

If[FromDigits[music3] == 1, 
 mma = {-20, -19, -17, -15, -13, -12, -10, -8, -7, -5, -3, -1, 0, 2, 
   4};
 mma1 = Partition[
   If[Count[mma, _]/2 \[Element] Integers, mma, 
    Join[mma, {RandomChoice[Take[mma, -1]]}]], {2}];
 mma2 = Partition[
   If[Count[mma, _]/3 \[Element] Integers, mma, 
    Join[mma, {RandomChoice[Take[mma, {-2, -1}]]}]], {3}];
 mma3 = Partition[
   If[Count[mma, _]/4 \[Element] Integers, mma, 
    Join[mma, {RandomChoice[Take[mma, {-3, -1}]]}]], {4}];
 mma4 = Partition[
   If[Count[mma, _]/5 \[Element] Integers, mma, 
    Join[mma, {RandomChoice[Take[mma, {-4, -1}]]}]], {5}];
 mmaa1 = Sound[
   Table[SoundNote[i1, SoundVolume -> 1/2], {i1, 
     Flatten[Table[
       RandomSample[
        Table[RandomSample[
          FromDigits[
           Take[Join[mma1, mma2, mma2, mma3, mma3, mma3, 
             mma4], {i}]]], {i, 1, 
          Count[Join[mma1, mma2, mma2, mma3, mma3, mma3, mma4], _]}]],
        22]]}], {0, 600}];
 mmaa2 = Sound[
   Table[SoundNote[i2, SoundVolume -> 1/2], {i2, 
     Flatten[
      Table[{-8, -8, -5, -5, -10, -10, -3, -3, -8, -8, -7, -7, -12, \
-12}, 64]]}], {0, 600}];
 mmaa3 = Sound[
   Table[SoundNote[i3, SoundVolume -> 7/12], {i3, 
     Flatten[Table[{-8, -8, -8, -3, -3, -3, -5, -5, -1, -1}, 
       80]]}], {0, 600}];
 mmaa4 = Sound[
   Table[SoundNote[i4, SoundVolume -> 1/3], {i4, 
     Flatten[Table[{-8, -5, -8, -5, -3, -5, -3, -5, -10, -10, 4, 4}, 
       100]]}], {0, 600}];
 Sound[{"Guitar", mmaa1, "PanFlute", mmaa2, "Bass", mmaa3, 
   "SynthDrum", mmaa4}], Null]

( just add this code to the game code and enjoy a new and a little more elaborate sample music )

Thanks.

POSTED BY: Claudio Chaib
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract