PDA

View Full Version : Riddle of Steel: combat code in R



JeenLeen
2017-08-30, 12:31 PM
I'm getting interested in Riddle of Steel, but the combat mechanics seem complicated enough that I think my real-life group wouldn't consider it. So, I'm thinking of writing some functions in the programming language R (since it's free) that do combat for you.

My question is for those of you who know Riddle of Steel is: what functions sound useful?

Here's what I'm considering:
1) have each character (PC or NPC) defined as a data frame or list, containing elements like:

Name
Attributes
Armor value over each body part
Proficiency level for their default weapon type
TN for their default weapon type
TN default for defense
current highest wound at each body part
current highest pain at each body part
the exchange they are in
the round they are in
current Health


I envision these functions:
atk (attacker, defender, aCP, dCP, amod=0, dmod=0, aTN='NA', dTN='NA')
where
attacker = the name of the data frame for the attacker
defender = the name of the data frame for the defender
aCP = number of CP the attacker is using to attack this exchange
dCP = as dCP, but for defender
amod = any modifier to the attacker's number of die (for example, put a 1 here if you get +1 due to attacking an easy to attack place or using SA)
dmod = as amod, but for defender
aTN = TN of the attack, if not the default used in the array
dTN = as aTN, but for defender

The function would do the math, declare the result, and tell how many CP are available for the next exchange (after looking at things like shock and pain).

Since the data frame remembers what exchange it is and what round, it can handle stuff like rolling for blood lost at the appropriate time, and for fatigue decreasing CP over time.

Other similar functions could handle situations when both attack. Casting a spell or doing ranged weapons doesn't work as well since those take additional time.

I'd also make functions like:
printme <--prints a character sheet, displaying the array and any current wounds
clean <-- removes the temporary things, like current wounds/pain/health and what exchange/round they are in
and potentially some functions to handle 2-vs-1 and 3-vs-1 combat situations.

Anyway, any recommendations or thoughts?

Lacco
2017-08-31, 05:45 AM
I'm no programmer (though I like making algorithms), but you should check the internet archive for www.driftwoodpublishing.com.

In the downloads section, there are two items that could help:
- working program for basic combat (it covers the core rules, no other sources), can be used for 2 player hot-seat combat,
- combat breakdown, a list of things to do within each combat round.

The issues I see with the stuff below:
- "attacker" and "defender" are not static; you can be attacker in one exchange and defender in second;
- initiative is more important than it sounds; it basically tells us how the round goes (red-red = both attack at once, no switching to defence, roll for REF/Atn of weapon who hits first; red-white = standard exchange, attacker attacks, defender defends; white-white = round passes as you circle around each other, nobody attacks) but there are some exceptions (e.g. switching from defence to offence is possible, but unless you steal initiative your blow lands second automatically = if you get wounded, the wound decreases your attack pool and your blow may even miss).

I would also recommend handing out pre-made sheets and going 1-on-1 arena-style one-shot :smallsmile:

warty goblin
2017-08-31, 11:38 AM
This is the sort of thing where a strongly object oriented language is really handy. R is not that language. I mean you can do it, it's just kludgy as all getout. For one thing R passes copies into functions, not references, and only supports a single return in a function. If your attacker and defender's data are both modified by an attack, you either have to mess around with modifying both of them inside the function, then returning them in a list and extracting them out of that list, or something complicated, scary and bad form where you reference objects outside of the function's namespace.

(There are ways to do more object oriented stuff in R, but given that basically nobody does this, I assume it's mostly terrible. Also R has three separate types of objects, because R is a genuinely stupid language.)


The language you probably want is Java, which is much harder to just pick up and run with, but will handle this sort of thing very nicely. Define each character as an object with whatever fields you need, write up some simple methods to access or modify those fields as needed. Then you just need an attack() and a isAttacked() method. Then if A is attacking B, you do A.attack(B), which triggers B's isAttacked() method, each of which updates each character's fields as necessary.

Python isn't a bad bet either, and is syntatically easier to deal with than Java.

JeenLeen
2017-08-31, 12:25 PM
lacco, thanks for those references. I'll check them out.


This is the sort of thing where a strongly object oriented language is really handy. R is not that language. I mean you can do it, it's just kludgy as all getout. For one thing R passes copies into functions, not references, and only supports a single return in a function. If your attacker and defender's data are both modified by an attack, you either have to mess around with modifying both of them inside the function, then returning them in a list and extracting them out of that list, or something complicated, scary and bad form where you reference objects outside of the function's namespace.

(There are ways to do more object oriented stuff in R, but given that basically nobody does this, I assume it's mostly terrible. Also R has three separate types of objects, because R is a genuinely stupid language.)


The language you probably want is Java, which is much harder to just pick up and run with, but will handle this sort of thing very nicely. Define each character as an object with whatever fields you need, write up some simple methods to access or modify those fields as needed. Then you just need an attack() and a isAttacked() method. Then if A is attacking B, you do A.attack(B), which triggers B's isAttacked() method, each of which updates each character's fields as necessary.

Python isn't a bad bet either, and is syntatically easier to deal with than Java.

All true. I've planned on going with 'bad form', having each PC and NPC defined in a variable (probably a list) and let the macro reference that list outside of itself. I haven't figured out exactly how to yet, but I figure something like:
Trish = #details for the PC named Trish
atk(attacker='Trish', ...)
and something in the function like eval(attacker) so that the character string sent into the function is used to find the variable outside of the function. If R had macro variables like SAS does, it would be easy... but if it does, I don't know how to do that.

I might try it with VBA within Microsoft Excel, since I've programmed in that a bit before and I know it can handle stuff like that. Plus, it'd be easy to store an NPC's sheet in Excel and have the macro reference that. That is, Excel can keep track of some of the book-keeping instead of the program itself.

I'm sure Java would be good, but I don't have experience with it. If I find time -- unlikely now, due to grad courses -- I might try it with Python. I'm mainly thinking of R because I have experience and my friends could use it for free.