Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 4 5 [6] 7 8 ... 13  All

Author Topic: Dominiate: a Dominion simulator that runs on the Web  (Read 247980 times)

0 Members and 1 Guest are viewing this topic.

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #125 on: November 03, 2011, 12:05:43 pm »
0

Fixed.
Logged

Toskk

  • Young Witch
  • ****
  • Offline Offline
  • Posts: 132
  • Respect: +44
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #126 on: November 04, 2011, 04:24:27 pm »
0

Is it possible for the AI strategies in Dominiate to access the turnsTaken variable? I'm working on optimizing a few buy decisions, and knowing how many turns have passed already could be very helpful.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #127 on: November 04, 2011, 04:33:33 pm »
+1

Yep. It's a variable on the PlayerState, so you access it with "my.turnsTaken".
Logged

Toskk

  • Young Witch
  • ****
  • Offline Offline
  • Posts: 132
  • Respect: +44
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #128 on: November 04, 2011, 04:36:59 pm »
0

Excellent, thanks. :)
Logged

Toskk

  • Young Witch
  • ****
  • Offline Offline
  • Posts: 132
  • Respect: +44
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #129 on: November 04, 2011, 07:13:19 pm »
0

Ok, one more question.. the function my.numCardsInDeck().. is that returning the number of cards in the deck *and* hand and discard pile (the sum of all cards the player owns), or just the number of cards actually in the player's deck (not including those in hand or in the discard pile) at that moment? If it's the latter, is there some function to determine the total number of cards in deck, hand, and discard pile?
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #130 on: November 05, 2011, 05:11:48 am »
0

In the code of Dominiate, I try to use "deck" to refer to all the cards that will be counted at the end of the game, and I call the pile you draw from the "draw pile". I realize I haven't entirely been consistent, but it's better than the rules, which don't distinguish them at all.

The deck in Dominiate is currently defined as the contents of your draw pile, discard pile, hand, cards in play, cards set aside, cards under Havens, native village mat, and island mat. Come to think of it, maybe the island mat shouldn't actually count, and my.getVP() should instead count your deck plus your island mat.
Logged

Qvist

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2400
  • Shuffle iT Username: Qvist
  • Respect: +4085
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #131 on: November 23, 2011, 07:36:42 am »
0

So, now I tested Dominiate and I must admit, it's great. Kudos, great work.

Here's a bot, I did not get to work for Geronimoo's Simulator and it works quite well as it beats Double Jack for instance:
Code: [Select]
{
  name: 'Mint + Fool\'s Gold'
  author: 'Qvist'
  requires: ["Mint", "Fool's Gold", "Steward"]
  gainPriority: (state, my) -> [
    "Province"
    "Duchy" if state.gainsToEndGame() <= 5
    "Estate" if state.gainsToEndGame() <= 2
    "Mint" if my.countInDeck("Mint") == 0 && my.countInPlay("Copper") >= 4
    "Steward" if my.countInDeck("Steward") == 0
    "Fool's Gold"
  ]
}

But I see still some poor decisions.
As I understand it right you can basically program your AI here as complex as you want by overriding the respectice methods which is very nice for a programmer like me. But I have no experience with CoffeeScript. I looked into your code and understand it most of the times, but I couldn't understand benefitValue for example. As I understand it right choice cards like Steward use it. I don't know how this function works, but it seems to make wrong decisions. Maybe you can either help me to find the reason for these following issues or you can explain me the benefitValue method or you can explain me how to override it.

Here are the problems:
Hand: Mint, Steward, Fool's Gold, Fool's Gold, Fool's Gold
I have enough money for a Province, so normally I would mint a Fool's Gold. But the AI takes the +2$ from Steward.

Hand: Mint, Steward, Province, Fool's Gold, Fool's Gold
I have not enough money for a Province, so normally play the Steward and hope to draw another Fool's Gold. But the AI takes the +$2 from Steward although I have no card for $6 or $7 in my gainPriority.

Can you help me?

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #132 on: November 23, 2011, 08:00:00 am »
0

So, now I tested Dominiate and I must admit, it's great. Kudos, great work.

Here's a bot, I did not get to work for Geronimoo's Simulator and it works quite well as it beats Double Jack for instance:
Code: [Select]
{
  name: 'Mint + Fool\'s Gold'
  author: 'Qvist'
  requires: ["Mint", "Fool's Gold", "Steward"]
  gainPriority: (state, my) -> [
    "Province"
    "Duchy" if state.gainsToEndGame() <= 5
    "Estate" if state.gainsToEndGame() <= 2
    "Mint" if my.countInDeck("Mint") == 0 && my.countInPlay("Copper") >= 4
    "Steward" if my.countInDeck("Steward") == 0
    "Fool's Gold"
  ]
}

But I see still some poor decisions.
As I understand it right you can basically program your AI here as complex as you want by overriding the respectice methods which is very nice for a programmer like me. But I have no experience with CoffeeScript. I looked into your code and understand it most of the times, but I couldn't understand benefitValue for example. As I understand it right choice cards like Steward use it. I don't know how this function works, but it seems to make wrong decisions. Maybe you can either help me to find the reason for these following issues or you can explain me the benefitValue method or you can explain me how to override it.

Here are the problems:
Hand: Mint, Steward, Fool's Gold, Fool's Gold, Fool's Gold
I have enough money for a Province, so normally I would mint a Fool's Gold. But the AI takes the +2$ from Steward.

Hand: Mint, Steward, Province, Fool's Gold, Fool's Gold
I have not enough money for a Province, so normally play the Steward and hope to draw another Fool's Gold. But the AI takes the +$2 from Steward although I have no card for $6 or $7 in my gainPriority.

Can you help me?

Hi. I'm not as into all of this as rspeer, so maybe he corrects me, but afaiu:
You should be able to overwrite every function by just defining it in the same file as the gainPriority. The file you are writing defines a new class "XYZ-AI" derived from the basicAI-class, you can just redefine every function, as you already do with the gainPriority (which is also defined in basicAI.coffee). I think there is much potential (possibly also for speed) by just defining your own actionPriority, as the standard one returns a very long list, because it has to cover all possible cards, and not the 3-10 you usually care for.

In you're example (very easy case, probably you have to be a litte more sophisticated):
1) C&P the actionPriority from https://github.com/rspeer/dominiate/blob/de69485f38af8f0be78e4f2fb984bcfbeb6fb238/basicAI.coffee
2) [optional, but strongly recommended, for performance and readability] Delete every card you don't care for
3) Think about which card you want to play in which situation and list them in the same way as you do with buyPriority.  In your case probably something like
Code: [Select]
actionPriority: (state, my, skipMultipliers = false) -> [
  "Mint" if $functionThatTellsMeHowMuchMoneyIsInMyHand>=8
  "Steward"
  "Mint"
]
getting the right choice for Steward might be a little bit more difficult. The relevant function is benefitValue(state, choice, my) [in the same file]. You might want to try to lower the value for coins, or increase it for draw under certain conditions.

Edit: You might also want to change the MintValue-function, as at the moment it decides what to mint from the price, so minting silver over Fool's Gold. Something like
Code: [Select]
mintValue (state, card, my) ->
  mv = card.cost
  if c[card]=="Fool's Gold" mv=4
  return mv
« Last Edit: November 23, 2011, 08:05:40 am by DStu »
Logged

Qvist

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2400
  • Shuffle iT Username: Qvist
  • Respect: +4085
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #133 on: November 23, 2011, 09:30:54 am »
0

Thanks for the advice.
It already helped me a lot.

So I edited some functions for this bot and it already beats most of the other implemented ones.

Code: [Select]
{
  name: 'Mint + Fool\'s Gold'
  author: 'Qvist'
  requires: ["Mint", "Fool's Gold", "Steward"]
  gainPriority: (state, my) -> [
    "Province"
    "Duchy" if state.gainsToEndGame() <= 5
    "Estate" if state.gainsToEndGame() <= 2
    "Mint" if my.countInDeck("Mint") == 0 && my.countInPlay("Copper") >= 4
    "Steward" if my.countInDeck("Steward") == 0
    "Fool's Gold"
  ]
  actionPriority: (state, my, skipMultipliers = false) -> [
    "Mint" if this.pessimisticMoneyInHand(state)>=8
    "Steward"
    "Mint"
  ]
  trashPriority: (state, my) -> [
    "Curse"
    "Potion"
    "Estate" if state.gainsToEndGame() > 4
    "Copper" if my.getTotalMoney() > 4
    "Estate" if state.gainsToEndGame() > 2
    "Silver"
  ]
  benefitValue: (state, choice, my) ->
    cardValue = 2
    coinValue = 1
    trashValue = 4      # if there are cards we want to trash

    if my.ai.wantsToTrash(state) < (choice.trash ? 0) || my.getDeck().length <= 5
      trashValue = -4
    if this.pessimisticMoneyInHand(state) >= 8
      cardValue = -2
      coinValue = -1
    else if this.pessimisticMoneyInHand(state) >= 6
      cardValue = -2
     
    value = cardValue * (choice.cards ? 0)
    value += coinValue * (choice.coins ? 0)
    value += trashValue * (choice.trash ? 0)
    value

}

But there's still one thing I'm missing that's making problems. The benefitValue seems to only trigger after already playing it. I'd like to check benefitValue before choosing to play it.

Something like that:
Code: [Select]
actionPriority: (state, my, skipMultipliers = false) -> [
    "Mint" if this.pessimisticMoneyInHand(state)>=8
    "Steward" if benefitValue>0
    "Mint"
  ]

Is this possible?

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #134 on: November 23, 2011, 09:58:50 am »
0

So I edited some functions for this bot and it already beats most of the other implemented ones.
Some remarks:
You probably want to use my.getAvailableMoney() instead of pessimisticMoneyInHand() in gainPriority. The latter is written for use during the actionphase, where you have to guess how much money you will end with after the turn, while when you buy something, you are already in the buyphase and know how much money you have. So the function is much easier there.

Quote
But there's still one thing I'm missing that's making problems. The benefitValue seems to only trigger after already playing it. I'd like to check benefitValue before choosing to play it.

Something like that:
Code: [Select]
actionPriority: (state, my, skipMultipliers = false) -> [
    "Mint" if this.pessimisticMoneyInHand(state)>=8
    "Steward" if benefitValue>0
    "Mint"
  ]

Is this possible?
benefitValue wants a choice as parameter. So if I see it correctly, you should use
Code: [Select]
  "Steward" if benefitValue(state, [{cards: 2}, {coins: 2}, {trash: 2}], my) > 0
Don't know if it that can be done more elegantly.
Logged

Qvist

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2400
  • Shuffle iT Username: Qvist
  • Respect: +4085
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #135 on: November 23, 2011, 10:08:33 am »
0

So I edited some functions for this bot and it already beats most of the other implemented ones.
Some remarks:
You probably want to use my.getAvailableMoney() instead of pessimisticMoneyInHand() in gainPriority. The latter is written for use during the actionphase, where you have to guess how much money you will end with after the turn, while when you buy something, you are already in the buyphase and know how much money you have. So the function is much easier there.

Thanks for the tip, but that doesn't work for Fool's Gold as I've already tried that. That function only counts the coins which are defined in the card, which is 1 for Fool's Gold. So I have to simulate all cards already have been played, for that I have use pessimisticMoneyInHand() or write a new function. But pessimisticMoneyInHand() does its job.

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #136 on: November 23, 2011, 10:18:52 am »
0

So I edited some functions for this bot and it already beats most of the other implemented ones.
Some remarks:
You probably want to use my.getAvailableMoney() instead of pessimisticMoneyInHand() in gainPriority. The latter is written for use during the actionphase, where you have to guess how much money you will end with after the turn, while when you buy something, you are already in the buyphase and know how much money you have. So the function is much easier there.

Thanks for the tip, but that doesn't work for Fool's Gold as I've already tried that. That function only counts the coins which are defined in the card, which is 1 for Fool's Gold. So I have to simulate all cards already have been played, for that I have use pessimisticMoneyInHand() or write a new function. But pessimisticMoneyInHand() does its job.

Oh, you are right. But there should be a method at this point, the treasures are played. I will have a look.

Edit: Probably it's just my.coins ?
« Last Edit: November 23, 2011, 10:25:06 am by DStu »
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #137 on: November 23, 2011, 06:06:32 pm »
0

my.coins is right for counting treasures (and +$ actions) that are already played, and Qvist is correct that pessimisticMoneyInHand() is the only way to count treasures you haven't played yet when choosing an action.

Would it be useful for other things as well, if we updated getAvailableMoney() to count things like Bank and Fool's Gold appropriately? It'd still have to treat Venture as if it were a copper or silver, but the other treasures can be improved.
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #138 on: November 24, 2011, 02:57:07 am »
0

my.coins is right for counting treasures (and +$ actions) that are already played, and Qvist is correct that pessimisticMoneyInHand() is the only way to count treasures you haven't played yet when choosing an action.
That's right, but I in gainPriority, they should have all been played. In the decision for the Steward, you need pessimiticMoneyInHand()

Quote
Would it be useful for other things as well, if we updated getAvailableMoney() to count things like Bank and Fool's Gold appropriately? It'd still have to treat Venture as if it were a copper or silver, but the other treasures can be improved.
I don't want to look up the code now, but from what I remember, would that not exactly end up with pessimisticMoneyInHand()? AFAIR, pessimisticMoneyInHand() gives you the amount of $ you would end up with if you would just play everything you have, and draw nothing in this process. That is about what you would have to do if you want to improve getAvailableMoney().
Or you could even improve this (by finding at least as many Coppers as you have with the Ventures for example), but then you could also improve pessimisticMoneyInHand.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #139 on: November 24, 2011, 07:36:49 am »
0

Well, for one thing, getAvailableMoney is way faster than pessimisticMoneyInHand.

The main difference would be that it wouldn't take into account if you have actions remaining and +$ action cards in your hand.
Logged

Jorbles

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1468
  • Respect: +531
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #140 on: November 24, 2011, 02:46:36 pm »
0

I've coded Golem, Farmland, Silk Road, and Tunnel. I still need to implement Tunnel's reaction, and then I'll request a pull. I'll probably do Pearl Diver too, to finish off the "easy" card list.

Was going to say I found a bug in Tunnel, but it seems that it's just not coded yet. (or maybe it is and it just hasn't been moved into the newest build). Anyhow I guess I will have to wait to try my Venture, Tunnel, Moneylender bot (see below). Love the simulator now that I've started playing with it.

Code: [Select]
#VentureTunnelMoneylender
{
 name: 'VTM'
 author: 'Jorbles'
 requires: ['Venture', 'Tunnel', 'Moneylender']
 gainPriority: (state, my) -> [
   "Colony" if my.countInDeck('Platinum') > 0
   "Province" if state.countInSupply('Colony') <= 6 \
              or state.countInSupply('Province') <= 6

   "Duchy" if 0 < state.gainsToEndGame() <= 5
   "Estate" if 0 < state.gainsToEndGame() <= 2
   "Platinum"
   "Venture" if my.countInDeck('Tunnel') >= 1
   "Gold"
   "Venture"
   "Moneylender" if my.countInDeck('Moneylender') == 0
   "Silver" if my.countInDeck('Silver') < 1
   "Tunnel"
 ]
}
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #141 on: November 24, 2011, 03:39:02 pm »
0

On github it seems fully implemented. what is the bug?
Logged

Jorbles

  • Saboteur
  • *****
  • Offline Offline
  • Posts: 1468
  • Respect: +531
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #142 on: November 24, 2011, 05:15:27 pm »
0

Really? Because when I try it, there seems to be no reaction on discards (ie. discarding Tunnels doesn't cause Gold gains, which it should default to).
For example:
Code: [Select]
== VTM's turn 12 ==
VTM plays Silver.
VTM plays Copper.
VTM plays Copper.
VTM plays Venture.
...VTM reveals [Tunnel, Tunnel, Copper].
...VTM discards [Tunnel, Tunnel].
...playing Copper.
Coins: 6, Potions: 0, Buys: 1
VTM buys Venture.
VTM draws 5 cards: [Estate, Venture, Moneylender, Tunnel, Tunnel].
Maybe the trigger for the reaction isn't set up for this kind of discard?
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #143 on: November 25, 2011, 01:48:33 am »
0

Maybe the trigger for the reaction isn't set up for this kind of discard?
Yepp. Seems like the function "dig", which is called by Venture does not call the function "handleDiscard", which cares for the reaction.
Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #144 on: November 25, 2011, 05:02:56 am »
0

Fixed.

When I changed the discarding code to check for discard reactions, I forgot to change dig because I was mostly looking in cards.coffee.
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #145 on: November 25, 2011, 10:55:10 am »
0

@performance:

I just tested my hypothesis that producing manual actionPriorities would fasten the simulator, and for JoaT:BankWharfs in Chromium fast mode I get 1000 games from 24secs down to 14 secs. So my question:
Do you see any possibility to let the simulator compile a custom actionPriority before starting based on the one in basicAI.coffee, stripped to the cards that are specified in buyPriority? Or at least in requires?
In loadStrategy (play.coffee) you overwrite with "ai[key] = value" by what is specified in the browser. Now if we could treat the function actionPriority (from basicAI.coffee) as a string, is might be possible to overwrite ai[actionPriority] by something which we calculate at runtime? If that's true, than we might condense the actionPriority to the cards that really are listed in buyPriority.

Possible issues: Swindler?
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #146 on: November 28, 2011, 12:05:06 pm »
0

So I tried what I proposed, and in principle it works. There is a little problem I don't know how to solve:
The function I may modifie at runtime is already compiled to Javascript, so the code does not looking so nicely anymore. It basically is
Code: [Select]
return [my.menagerieDraws() === 3 ? "Menagerie" : void 0, my.shantyTownDraws(true) === 2 ? "Shanty Town" : void 0, my.countInHand("Province") > 0 ? "Tournament" : void 0, wantsToPlayMultiplier ? "Throne Room" : void 0, wantsToPlayMultiplier ? "King's Court" : void 0, state.gainsToEndGame() >= 5 || (_ref = state.cardInfo.Curse, __indexOf.call(my.draw, _ref) >= 0) ? "Lookout" : void 0, "Cartographer", "Bag of Gold", "Apothecary", "Scout:",
so basically a list. I tried to split the string at "," to get the single entries, which also works quite well, the only problem is expressions like
Code: [Select]
(_ref = state.cardInfo.Curse, __indexOf.call(my.draw, _ref) >= 0) ? "Lookout" : void 0
which gets ripped apart in the __indexOf.call-function.  Is there any easy way to get around this, so say split the string at ",", conditioned on no open brackets?
Logged

danshep

  • Navigator
  • ****
  • Offline Offline
  • Posts: 70
  • Respect: +15
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #147 on: November 28, 2011, 07:05:07 pm »
0

I think what you want to be doing there is creating a method that returns action priorities only for cards in the supply.

{{{
  defaultActionPriority: (state) -> [
    ((state, my) -> "Menagerie" if my.menagerieDraws() == 3 ) if state.countInSupply("Managerie") > 0
    ((state, my) -> "Shanty Town" if my.shantyTownDraws(true) == 2 ) if state.countInSupply("Shanty Town") > 0
    ... etc ...
  ]
}}}

And then, you compile that once into an array of functions that only includes the actions available (I'm guessing countInSupply is wrong there). Then you'll have a much shorter array to call.

Actually, all the choice functions would work better if they were functions, so that you could short-circuit the function as soon as it hits a valid choice, rather than compiling it all into a 100 element array that may never get the last 99 elements read.

Just changing the chooseByPriorityAndValue method would allow all the choices in choice arrays to be wrapped in functions to be lazily evaluated:

{{{
      for preference in priority
        if preference of function
          preference = preference.bind(this)(state, my)
        if preference is null and null in choices
          return null
        if choiceSet[preference]?
          return choiceSet[preference]
}}}





Logged

rspeer

  • Witch
  • *****
  • Offline Offline
  • Posts: 469
  • Respect: +877
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #148 on: November 29, 2011, 03:11:46 am »
0

Okay, I don't follow what danshep just did, but I agree that lazy evaluation would be a great thing if we could get it without harming the readability of the strategies.

I think I do understand what DStu wants to do, but trying to reverse-engineer things from the JavaScript of the function is probably going to be a horrifying way to do it.

A thought I had after trying to sort out DStu's post is that we could have strategies define a shorter version of actionPriority that uses only their preferred cards, and fall back on the long one if they get a card swindled (or masqueraded) into their deck that's neither a basic card nor in their "requires" list.
Logged

DStu

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2627
  • Respect: +1490
    • View Profile
Re: Dominiate: a Dominion simulator that runs on the Web
« Reply #149 on: November 29, 2011, 04:14:27 am »
0

With the Javascript it's actually not that bad. There is a bunch of code at the beginning for KC/TR that I have ignored until now,  but that's just one block that you take or leave depending on KC/TR in the deck.
There are the preprocessed functions at the beginning which one could just also always take, or we don't do preprocessing anymore, as in the stripped function it will have no benefit, once it works.

Ignoring these two (solvable) points, you have to  process the last important line of JS, where the array is constructed. Splitting it at "," almost really works, there are I think only 6 lines (of two different types) where it fails because there's a comma in a function. If you don't care about them (I tried JoaT vs Wharf, where you don't have the problems), my (say) 10 lines of code already work.
The long time problem is of course to keep this parsing up to date if the actionPriority changes, and to notice errors once they occur.

PS: Have not read danshep in detail, but that also sounds interesting.

Edit: In short what I want to do, as I now really now what it is:
When generating a new strategy in play.coffee, to define the actionPriortiy of this bot, I want to take the actionPriority-function from basicAI.coffee, and delete all lines from the list that are not used by the bot (not listed in "requieres"). This can work as you can handle the function as a string, but it's already Javascript and not Coffeescript anymore, especially they are now all in one single line, seperated by ",". Problem is that this seperations are not the only ","s in the string.

Edit2: Perhaps I should parse the string lowlevel char for char. Then I can just count braces, or handle them recursively, which is not really difficult as I don't have to understand anything and just identify the parts between two "real" ","s. And performance should not be important at this part, because this is only done twice per run.
« Last Edit: November 29, 2011, 04:42:15 am by DStu »
Logged
Pages: 1 ... 4 5 [6] 7 8 ... 13  All
 

Page created in 0.123 seconds with 21 queries.