[#397093] Using binding + set_trace_func to capture execution state — Reginald Tan <lists@...>

Hi guys, I'm interested in building a program that will display the

18 messages 2012/07/03
[#397097] Re: Using binding + set_trace_func to capture execution state — Peter Zotov <whitequark@...> 2012/07/03

Reginald Tan писал 03.07.2012 05:11:

[#397115] Copying Files — "Alex C." <lists@...>

Hi,

17 messages 2012/07/03

[#397165] Green threads in 1.9.* ? — rex goxman <lists@...>

I am new to Ruby. I am somewhat surprised that I was not able to find

56 messages 2012/07/04
[#397224] Re: Green threads in 1.9.* ? — rex goxman <lists@...> 2012/07/05

<<There are definitely many reasons to prefer native threads over green

[#397227] Re: Green threads in 1.9.* ? — Tony Arcieri <tony.arcieri@...> 2012/07/05

On Thu, Jul 5, 2012 at 6:38 AM, rex goxman <lists@ruby-forum.com> wrote:

[#397232] Re: Green threads in 1.9.* ? — rex goxman <lists@...> 2012/07/05

Tony Arcieri wrote in post #1067551:

[#397234] Re: Green threads in 1.9.* ? — Tony Arcieri <tony.arcieri@...> 2012/07/05

On Thu, Jul 5, 2012 at 10:26 AM, rex goxman <lists@ruby-forum.com> wrote:

[#397239] Re: Green threads in 1.9.* ? — rex goxman <lists@...> 2012/07/05

Tony Arcieri wrote in post #1067563:

[#397251] Re: Green threads in 1.9.* ? — Tony Arcieri <tony.arcieri@...> 2012/07/06

On Thu, Jul 5, 2012 at 12:31 PM, rex goxman <lists@ruby-forum.com> wrote:

[#397253] Re: Green threads in 1.9.* ? — rex goxman <lists@...> 2012/07/06

Tony Arcieri wrote in post #1067609:

[#397256] Re: Green threads in 1.9.* ? — Tony Arcieri <tony.arcieri@...> 2012/07/06

On Thu, Jul 5, 2012 at 8:24 PM, rex goxman <lists@ruby-forum.com> wrote:

[#397260] Re: Green threads in 1.9.* ? — Ryan Davis <ryand-ruby@...> 2012/07/06

[#397267] Re: Green threads in 1.9.* ? — Robert Klemme <shortcutter@...> 2012/07/06

On Fri, Jul 6, 2012 at 8:52 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:

[#397269] Re: Green threads in 1.9.* ? — rex goxman <lists@...> 2012/07/06

Robert Klemme wrote in post #1067663:

[#397185] Insert letters of the alphabet between the original letters of a string — Joao Silva <lists@...>

Hi All.

10 messages 2012/07/04

[#397198] the best way to match these domains. — Eliezer Croitoru <eliezer@...>

thanks in advance i need a bit help to break the ice that my head is in.

18 messages 2012/07/05
[#397202] Re: the best way to match these domains. — Robert Klemme <shortcutter@...> 2012/07/05

On Thu, Jul 5, 2012 at 4:13 AM, Eliezer Croitoru <eliezer@ngtech.co.il> wrote:

[#397245] Re: the best way to match these domains. — Eliezer Croitoru <eliezer@...> 2012/07/05

On 7/5/2012 10:03 AM, Robert Klemme wrote:

[#397258] Re: the best way to match these domains. — Robert Klemme <shortcutter@...> 2012/07/06

On Thu, Jul 5, 2012 at 10:40 PM, Eliezer Croitoru <eliezer@ngtech.co.il> wrote:

[#397316] Re: the best way to match these domains. — Eliezer Croitoru <eliezer@...> 2012/07/07

On 7/6/2012 9:21 AM, Robert Klemme wrote:

[#397415] Re: the best way to match these domains. — Robert Klemme <shortcutter@...> 2012/07/10

On Sat, Jul 7, 2012 at 5:32 AM, Eliezer Croitoru <eliezer@ngtech.co.il> wrote:

[#397464] Re: the best way to match these domains. — Eliezer Croitoru <eliezer@...> 2012/07/11

On 7/10/2012 12:08 PM, Robert Klemme wrote:

[#397416] learning by doing part 2 - tc game — "Sebastjan H." <lists@...>

Hi,

53 messages 2012/07/10
[#397418] Re: learning by doing part 2 - tc game — "Jan E." <lists@...> 2012/07/10

Hi,

[#397419] Re: learning by doing part 2 - tc game — "Sebastjan H." <lists@...> 2012/07/10

Yes, that would be ok, but that means that the player has to create all

[#397421] Re: learning by doing part 2 - tc game — Jes俍 Gabriel y Gal疣 <jgabrielygalan@...> 2012/07/10

On Tue, Jul 10, 2012 at 12:39 PM, Sebastjan H. <lists@ruby-forum.com> wrote:

[#397423] Re: learning by doing part 2 - tc game — "Jan E." <lists@...> 2012/07/10

"Jes=C3=BAs Gabriel y Gal=C3=A1n" <jgabrielygalan@gmail.com> wrote in pos=

[#397424] Re: learning by doing part 2 - tc game — "Sebastjan H." <lists@...> 2012/07/10

Jan E. wrote in post #1068109:

[#397426] Re: learning by doing part 2 - tc game — "Jan E." <lists@...> 2012/07/10

Sebastjan H. wrote in post #1068110:

[#397428] Re: learning by doing part 2 - tc game — "Sebastjan H." <lists@...> 2012/07/10

Jan E. wrote in post #1068114:

[#397429] Re: learning by doing part 2 - tc game — "Jan E." <lists@...> 2012/07/10

Sebastjan H. wrote in post #1068117:

[#397430] Re: learning by doing part 2 - tc game — "Sebastjan H." <lists@...> 2012/07/10

Jan E. wrote in post #1068119:

[#397435] Re: learning by doing part 2 - tc game — Jes俍 Gabriel y Gal疣 <jgabrielygalan@...> 2012/07/10

On Tue, Jul 10, 2012 at 3:18 PM, Sebastjan H. <lists@ruby-forum.com> wrote:

[#397608] undefined method error — deal bitte <lists@...>

rid.database_columns[session_db_array[0]]

17 messages 2012/07/17

[#397685] odd "system" command behaviour with CUI and GUI — Joel Pearson <lists@...>

Windows 7 64-bit, Ruby 1.9.3.

12 messages 2012/07/20

[#397738] Help a blind man getting ruby to work — "Morten T." <lists@...>

Hallo,

14 messages 2012/07/23

[#397806] Help with exercise from Chris Pine's Ruby Book: Sort without using .sort — "James H." <lists@...>

Hello all, I'm a n00b that's just getting into programming.

16 messages 2012/07/25

[#397817] modular exponentation with multiple exponents? — roob noob <lists@...>

I need to do a^b^c^d^e mod f

11 messages 2012/07/25

[#397903] How to test whether a session variable has a particular key — Doug Jolley <lists@...>

Although a session variable behaves like a hash for purposes of setting

11 messages 2012/07/30

Re: learning by doing part 2 - tc game

From: Jes俍 Gabriel y Gal疣 <jgabrielygalan@...>
Date: 2012-07-19 08:37:39 UTC
List: ruby-talk #397648
On Thu, Jul 19, 2012 at 10:13 AM, Sebastjan H. <lists@ruby-forum.com> wrote=
:
> "Jes=FAs Gabriel y Gal=E1n" <jgabrielygalan@gmail.com> wrote in post
> #1069191:
>> On Wed, Jul 18, 2012 at 2:02 PM, Sebastjan H. <lists@ruby-forum.com>
>> wrote:
>>>     player_hp =3D player_hp + card.armor
>>>     if ai_card.type =3D=3D "dragon" or ai_card.type =3D=3D "dire wolf"
>>>     ai_hp =3D ai_hp + ai_card.heal
>>>
>>>
>>>   @deck.delete(card)
>>>   @ai_deck.delete(ai_card)
>>>   puts "Player health is #{player_hp}."
>>>   puts "Ai health is #{ai_hp}."
>>> -------------------------------------------------------------
>>> thank you very much.
>>
>>
>> One approach that implies a huge refactor of your datastructures,
>> would be to have each card object implement its own logic on the game
>> state:
>>
>> class ArmorCard
>>   attr_reader :armor_level
>>   def initialize armor
>>     @armor_level =3D armor
>>   end
>>
>>   def perform_action game_state
>>     game_state.increment_player_hp(armor)
>>   end
>> end
>>
>> class HealingSpellCard
>>   attr_reader :spell_level
>>   def initialize spell_level
>>     @spell_level =3D spell_level
>>   end
>>
>>   def perform_action game_state
>>     game_state.increment_player_hp(spell_level * 2) #healing spells
>> heal double their level (example of spell logic)
>>   end
>> end
>>
>> Then you only need to call the perform_action method in each card
>> object. If you have common logic, such as attack card only differing
>> in name and attack value, but the attack logic is the same, then you
>> could model it with a class hierarchy:
>>
>> class Card
>>   def is_attack?
>>     false
>>   end
>> end
>>
>> class AttackCard < Card
>>   def is_attack?
>>     true
>>   end
>>
>>   def perform_action game_state
>>     game_state.increment_player_hp(armor)
>>     if game_state.ai_card.is_attack?
>>       game_state.increment_player_hp(-ai_card.attack)
>>     end
>>   end
>> end
>>
>> class Dragon < AttackCard
>>   attr_reader :armor, :attack
>>   def initialize armor, attack
>>     @armor =3D armor
>>     @attack =3D attack
>>   end
>> end
>>
>> And so on. You might have different classes depending on
>> characteristics or other ways to model it: maybe AttackCard,
>> SpellCard, etc could be modules you mixin in specific cards, for
>> example if some card can be both. Then maybe you could have a general
>> implementation of perform_action in the Card class. It depends.
>>
>> I hope this gives you some ideas.
>>
>> Jesus.
>
> Hi Jesus,
>
> I think you are right, this is probably the way to go and much better
> than branching or making different methods for different combinations of
> cards (would make game expansions impossible).
>
> However, I don't understand the "increment_player_hp". This is just your
> example, right? I'd have to define this I guess.

Yes, this is an example. You might have a GameState class with these
kind of utility methods, or any other mechanism for accessing the game
state. For example you could also have just an attr_accessor for
player_hp and do game_state.player_hp +=3D 5, but in general I like
those higher levell methods, because you might use them for integrity
checks, or triggering other logic that might otherwise need to repeat
everywhere. Another example: every time you modify the player_hp, you
might want to check if the player is dead and thus end the game or
whatever. If you have the logic for modifying that value in a single
place you only that logic in one place (DRY).

> Furthermore, according to your example above for the AttackCard there is
> only the definition for the player attack. I'd have to make two of
> those, also for the AI, right?. And for all other card types as well.

Yes, not sure how that works though. You and the AI each play a card,
then you activate the player's card that does something to both
players, then you activte the AI card which does something to both
players? Are the cards the same type for both? Do they do something
different depending if it's the player or the AI the one playing the
card? If the answers are yes, yes and no, you could do soemthing like:

# this would be the game loop making the player and the ai choose
cards and activated them in turn:
game_state.set_active_player :player
game_state.play_card_for_active_player
game_state.set_active_player :ai
game_state.play_card_for_active_player

class AttackCard < Card
  def is_attack?
    true
  end
  def perform_action game_state
    game_state.increment_active_player_hp(armor)
    if game_state.opponent_card.is_attack?
      game_state.increment_active_player_hp(-game_state.opponent_card.attac=
k)
    end
  end
end

So now, both players (player and ai) are the same from the card's
point of view. For a card there's just the "active player" who is the
one activating the card and the "opponent", who is... well, the
opponent :).

If, on the other hand, a card needs to know if it's the player or the
ai the one activating it, you can also model that information in the
game state and have the card check who is the active player. Another
option would be to have two sets of cards that implement the
appropriate logic, for example PlayerAttackCard and AIAttackCard and
so the decks don't share card implementations. So many
possibilities... :D.

Jesus.

In This Thread