SlideShare uma empresa Scribd logo
1 de 23
Ruby Warrior Presentation: Linear & OOP Solutions
by Sveatoslav Circel aka MEDBEDb

A triumphant quest of adventure, love & destiny all
within a few lines of code
https://www.bloc.io/ruby-warrior#/
Level 1
You see before yourself a long hallway with stairs
at the end. There is nothing in the way. Call
warrior.walk! to walk forward in the Player
'play_turn' method.
Solution:
class Player
def play_turn(warrior)
warrior.walk!
end

end
Level 2
It is too dark to see anything, but you smell
sludge nearby. Use warrior.feel.empty? to see if
there is anything in front of you, and
warrior.attack! to fight it. Remember, you can
only do one action (ending in !) per turn.
#LINEAR
Solution
class Player
def play_turn(warrior)
if warrior.feel.empty?
warrior.walk!
elsif warrior.feel.enemy?
warrior.attack!
end
end
end

#OBJECT ORIENTED
Solution
class Player
def initialize
@max_health = 20
end
def attacks(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end
def play_turn(warrior)
attacks(warrior)
end
end
Level 3
The air feels thicker than before. There must be
a horde of sludge. Be careful not to die! Use
warrior.health to keep an eye on your health, and
warrior.rest! to earn 10% of max health back.
#LINEAR
Solution
class Player
def play_turn(warrior)
if warrior.feel.empty? and warrior.health == 20
warrior.walk!
elsif warrior.feel.empty? and warrior.health < 20
warrior.rest!
elsif warrior.feel.enemy?
warrior.attack!
end
end
end

#OBJECT ORIENTED
Solution
class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
end
def attacks(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end

def play_turn(warrior)
if warrior.feel.empty? and warrior.health < @mid_health
warrior.rest!
else
attacks(warrior)
end
end
end
Level 4
You can hear bow strings being stretched. No new abilities
this time, but you must be careful not to rest while taking
damage. Save a @health instance variable and compare it
on each turn to see if you're taking damage.
#LINEAR
Solution
class Player
def play_turn(warrior)
@max_health = 20
@current_health = warrior.health
if warrior.feel.empty? and warrior.health == @max_health
warrior.walk!
elsif warrior.feel.empty? and @current_health >= @health
warrior.rest!
elsif warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
@health = warrior.health
end
end

#OBJECT ORIENTED
Solution
class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
@last_health = @max_health
end
def attacks(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end

def diminishing_health(warrior)
warrior.health < @last_health
end
def play_turn(warrior)
if diminishing_health(warrior)
attacks(warrior)
elsif !diminishing_health(warrior) and warrior.health < @max_health
warrior.rest!
else
attacks(warrior)
end
@last_health = warrior.health
end
end
Level 5
You hear cries for help. Captives must need
rescuing. Use warrior.feel.captive? to see if there
is a captive and warrior.rescue! to rescue him.
Don't attack captives.
#LINEAR
Solution
class Player
def play_turn(warrior)
@max_health = 20
@current_health = warrior.health
if warrior.feel.empty? and warrior.health == @max_health
warrior.walk!
elsif warrior.feel.empty? and @current_health >= @health
warrior.rest!
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
@health = warrior.health
end
end

#OBJECT ORIENTED
Solution
class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
@last_health = @max_health
end
def movement(warrior)
if warrior.feel.enemy?
attacks(warrior)
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
end
def attacks(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end

def diminishing_health(warrior)
warrior.health < @last_health
end
def play_turn(warrior)
if diminishing_health(warrior)
movement(warrior)
elsif !diminishing_health(warrior)
and warrior.health < @max_health
warrior.rest!
else
movement(warrior)
end
@last_health = warrior.health
end
end
Level 6
The wall behind you feels a bit further away in
this room. And you hear more cries for help. You
can walk backward by passing ':backward' as an
argument to walk!. Same goes for feel, rescue!
and attack!. Archers have a limited attack
distance.
#LINEAR
Solution

#OBJECT ORIENTED
Solution

class Player
def play_turn(warrior)
@maxlas_health = 20
@danger_health = 9
@current_health = warrior.health
if warrior.feel.empty? and warrior.health == @max_health
warrior.walk!
elsif warrior.feel.empty? and @current_health >= @health
warrior.rest!
elsif warrior.health < @danger_health and @current_health < @health
warrior.walk!(:backward)
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
@health = warrior.health
end
end

class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
@last_health = @max_health
end
def movement(warrior)
if warrior.feel.enemy?
attacks(warrior)
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
end
def attacks(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end

def diminishing_health(warrior)
warrior.health < @last_health
end
def play_turn(warrior)
if diminishing_health(warrior)
and warrior.health <= @mid_health
warrior.walk!(:backward)
elsif diminishing_health(warrior)
movement(warrior)
elsif !diminishing_health(warrior)
and warrior.health < @max_health
warrior.rest!
else
movement(warrior)
end
@last_health = warrior.health
end
end
Level 7
You feel a wall right in front of you and an
opening behind you. You are not as effective at
attacking backward. Use warrior.feel.wall? and
warrior.pivot! to turn around.
#LINEAR
Solution

#OBJECT ORIENTED
Solution

class Player
def play_turn(warrior)
@max_health = 20
@current_health = warrior.health
@danger_health = 9
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.empty? and warrior.health == @max_health
warrior.walk!
elsif warrior.feel.empty? and @current_health >= @health
warrior.rest!
elsif warrior.health < @danger_health and @current_health < @health
warrior.walk!(:backward)
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
@health = warrior.health
end
end

class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
@last_health = @max_health
end
def movement(warrior)
if warrior.feel.enemy?
attacks(warrior)
elsif warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
end
def attacks(warrior)
if warrior.feel.enemy?
warrior.attack!
else
warrior.walk!
end
end

def diminishing_health(warrior)
warrior.health < @last_health
end
def play_turn(warrior)
if diminishing_health(warrior)
and warrior.health <= @mid_health
warrior.walk!(:backward)
elsif diminishing_health(warrior)
movement(warrior)
elsif !diminishing_health(warrior)
and warrior.health < @max_health
warrior.rest!
else
movement(warrior)
end
@last_health = warrior.health
end
end
Level 8
You hear the mumbling of wizards. Beware of
their deadly wands! Good thing you found a bow.
Use warrior.look to determine your surroundings,
and warrior.shoot! to fire an arrow.
Linear Solution:
class Player
def play_turn(warrior)
@max_health = 20
@current_health = warrior.health
@danger_health = 9
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.look.find_all {|space| space.captive? }.size.to_i == 1
warrior.walk!
elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 2
warrior.shoot!
elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 3
warrior.shoot!
elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 0
warrior.walk!
elsif warrior.health < @danger_health and @current_health < @health
warrior.walk!(:backward)
else
warrior.shoot!
end
@health = warrior.health
end
end
class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
@last_health = @max_health
end

OOP Solution:

def get_enemies(warrior)
find_enemies(warrior) or find_enemies(warrior, :backward)
end

def movement(warrior)
if get_captives(warrior)
rescues(warrior)
elsif get_enemies(warrior)
attacks(warrior)
elsif warrior.feel.wall?
warrior.pivot!
else
warrior.walk!
end
end

def find_enemies(warrior, where = :forward)
enemy_spaces = warrior.look(where).find_all {|space| space.enemy? }
def attacks(warrior)
return enemy_spaces.any?
if warrior.feel.enemy?
end
warrior.attack!
elsif find_enemies(warrior)
def get_captives(warrior)
warrior.shoot!
find_captives(warrior) or find_captives(warrior, :backward)
end
end
end
def find_captives(warrior, where = :forward)
captive_spaces = warrior.look(where).find_all {|space| space.captive? } def diminishing_health(warrior)
warrior.health < @last_health
return captive_spaces.any?
end
end
def rescues(warrior)
if warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
end

def play_turn(warrior)
if diminishing_health(warrior)
and warrior.health <= @mid_health
warrior.walk!(:backward)
elsif diminishing_health(warrior)
movement(warrior)
elsif !diminishing_health(warrior)
and warrior.health < @max_health
warrior.rest!
elsif warrior.feel.captive?
warrior.rescue!
else
movement(warrior)
end
@last_health = warrior.health
end
end
Level 9
Time to hone your skills and apply all of the
abilities that you have learned. Watch your
back.
Linear Solution:
class Player
def play_turn(warrior)
@max_health = 20
@current_health = warrior.health
@mid_health = 9
@danger_health = 3
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.look(:backward).find_all {|space| space.enemy? }.size.to_i == 1
warrior.shoot!(:backward)
elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 2
warrior.shoot!
elsif warrior.health == @max_health
warrior.walk!
elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 0 and @current_health >= @health
warrior.rest!
elsif warrior.health < @mid_health and @current_health < @health
warrior.walk!(:backward)
else
warrior.shoot!
end
@health = warrior.health
end
end
OOP Solution:
class Player
def initialize
@max_health = 20
@mid_health = @max_health/2
@danger_health = @max_health * 3 / 4
@last_health = @max_health
end

def rescues(warrior)
if warrior.feel.captive?
warrior.rescue!
else
warrior.walk!
end
end

def get_enemies(warrior)
find_enemies(warrior) or
find_enemies(warrior, :backward)
end

def movement(warrior)
if get_captives(warrior)
rescues(warrior)
elsif get_enemies(warrior)
attacks(warrior)
elsif warrior.feel.wall?
warrior.pivot!
else
warrior.walk!
end
end

def find_enemies(warrior, where = :forward)
enemy_spaces =
warrior.look(where).find_all {|space|
space.enemy? }
return enemy_spaces.any?
end
def get_captives(warrior)
find_captives(warrior) or
find_captives(warrior, :backward)
end
def find_captives(warrior, where = :forward)
captive_spaces =
warrior.look(where).find_all {|space|
space.captive? }
return captive_spaces.any?
end

def attacks(warrior)
if warrior.feel(:backward).enemy?
warrior.pivot!
elsif warrior.feel.enemy?
warrior.attack!
elsif
find_enemies(warrior, :backward)
warrior.shoot!(:backward)
elsif find_enemies(warrior)
warrior.shoot!
end
end

def diminishing_health(warrior)
warrior.health < @last_health
end
def play_turn(warrior)
if diminishing_health(warrior) and warrior.health <= @mid_health
warrior.walk!(:backward)
elsif diminishing_health(warrior)
movement(warrior)
elsif !diminishing_health(warrior) and warrior.health < @max_health
warrior.rest!
elsif warrior.feel.captive?
warrior.rescue!
else
movement(warrior)
end
@last_health = warrior.health
end
end
Ruby warrior presentation - Linear & oop solutions by Sveatoslav

Mais conteúdo relacionado

Último

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Último (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Ruby warrior presentation - Linear & oop solutions by Sveatoslav

  • 1. Ruby Warrior Presentation: Linear & OOP Solutions by Sveatoslav Circel aka MEDBEDb A triumphant quest of adventure, love & destiny all within a few lines of code https://www.bloc.io/ruby-warrior#/
  • 2.
  • 3. Level 1 You see before yourself a long hallway with stairs at the end. There is nothing in the way. Call warrior.walk! to walk forward in the Player 'play_turn' method.
  • 5. Level 2 It is too dark to see anything, but you smell sludge nearby. Use warrior.feel.empty? to see if there is anything in front of you, and warrior.attack! to fight it. Remember, you can only do one action (ending in !) per turn.
  • 6. #LINEAR Solution class Player def play_turn(warrior) if warrior.feel.empty? warrior.walk! elsif warrior.feel.enemy? warrior.attack! end end end #OBJECT ORIENTED Solution class Player def initialize @max_health = 20 end def attacks(warrior) if warrior.feel.enemy? warrior.attack! else warrior.walk! end end def play_turn(warrior) attacks(warrior) end end
  • 7. Level 3 The air feels thicker than before. There must be a horde of sludge. Be careful not to die! Use warrior.health to keep an eye on your health, and warrior.rest! to earn 10% of max health back.
  • 8. #LINEAR Solution class Player def play_turn(warrior) if warrior.feel.empty? and warrior.health == 20 warrior.walk! elsif warrior.feel.empty? and warrior.health < 20 warrior.rest! elsif warrior.feel.enemy? warrior.attack! end end end #OBJECT ORIENTED Solution class Player def initialize @max_health = 20 @mid_health = @max_health/2 end def attacks(warrior) if warrior.feel.enemy? warrior.attack! else warrior.walk! end end def play_turn(warrior) if warrior.feel.empty? and warrior.health < @mid_health warrior.rest! else attacks(warrior) end end end
  • 9. Level 4 You can hear bow strings being stretched. No new abilities this time, but you must be careful not to rest while taking damage. Save a @health instance variable and compare it on each turn to see if you're taking damage.
  • 10. #LINEAR Solution class Player def play_turn(warrior) @max_health = 20 @current_health = warrior.health if warrior.feel.empty? and warrior.health == @max_health warrior.walk! elsif warrior.feel.empty? and @current_health >= @health warrior.rest! elsif warrior.feel.enemy? warrior.attack! else warrior.walk! end @health = warrior.health end end #OBJECT ORIENTED Solution class Player def initialize @max_health = 20 @mid_health = @max_health/2 @last_health = @max_health end def attacks(warrior) if warrior.feel.enemy? warrior.attack! else warrior.walk! end end def diminishing_health(warrior) warrior.health < @last_health end def play_turn(warrior) if diminishing_health(warrior) attacks(warrior) elsif !diminishing_health(warrior) and warrior.health < @max_health warrior.rest! else attacks(warrior) end @last_health = warrior.health end end
  • 11. Level 5 You hear cries for help. Captives must need rescuing. Use warrior.feel.captive? to see if there is a captive and warrior.rescue! to rescue him. Don't attack captives.
  • 12. #LINEAR Solution class Player def play_turn(warrior) @max_health = 20 @current_health = warrior.health if warrior.feel.empty? and warrior.health == @max_health warrior.walk! elsif warrior.feel.empty? and @current_health >= @health warrior.rest! elsif warrior.feel.enemy? warrior.attack! elsif warrior.feel.captive? warrior.rescue! else warrior.walk! end @health = warrior.health end end #OBJECT ORIENTED Solution class Player def initialize @max_health = 20 @mid_health = @max_health/2 @last_health = @max_health end def movement(warrior) if warrior.feel.enemy? attacks(warrior) elsif warrior.feel.captive? warrior.rescue! else warrior.walk! end end def attacks(warrior) if warrior.feel.enemy? warrior.attack! else warrior.walk! end end def diminishing_health(warrior) warrior.health < @last_health end def play_turn(warrior) if diminishing_health(warrior) movement(warrior) elsif !diminishing_health(warrior) and warrior.health < @max_health warrior.rest! else movement(warrior) end @last_health = warrior.health end end
  • 13. Level 6 The wall behind you feels a bit further away in this room. And you hear more cries for help. You can walk backward by passing ':backward' as an argument to walk!. Same goes for feel, rescue! and attack!. Archers have a limited attack distance.
  • 14. #LINEAR Solution #OBJECT ORIENTED Solution class Player def play_turn(warrior) @maxlas_health = 20 @danger_health = 9 @current_health = warrior.health if warrior.feel.empty? and warrior.health == @max_health warrior.walk! elsif warrior.feel.empty? and @current_health >= @health warrior.rest! elsif warrior.health < @danger_health and @current_health < @health warrior.walk!(:backward) elsif warrior.feel.enemy? warrior.attack! elsif warrior.feel.captive? warrior.rescue! else warrior.walk! end @health = warrior.health end end class Player def initialize @max_health = 20 @mid_health = @max_health/2 @last_health = @max_health end def movement(warrior) if warrior.feel.enemy? attacks(warrior) elsif warrior.feel.captive? warrior.rescue! else warrior.walk! end end def attacks(warrior) if warrior.feel.enemy? warrior.attack! else warrior.walk! end end def diminishing_health(warrior) warrior.health < @last_health end def play_turn(warrior) if diminishing_health(warrior) and warrior.health <= @mid_health warrior.walk!(:backward) elsif diminishing_health(warrior) movement(warrior) elsif !diminishing_health(warrior) and warrior.health < @max_health warrior.rest! else movement(warrior) end @last_health = warrior.health end end
  • 15. Level 7 You feel a wall right in front of you and an opening behind you. You are not as effective at attacking backward. Use warrior.feel.wall? and warrior.pivot! to turn around.
  • 16. #LINEAR Solution #OBJECT ORIENTED Solution class Player def play_turn(warrior) @max_health = 20 @current_health = warrior.health @danger_health = 9 if warrior.feel.wall? warrior.pivot! elsif warrior.feel.empty? and warrior.health == @max_health warrior.walk! elsif warrior.feel.empty? and @current_health >= @health warrior.rest! elsif warrior.health < @danger_health and @current_health < @health warrior.walk!(:backward) elsif warrior.feel.enemy? warrior.attack! elsif warrior.feel.captive? warrior.rescue! else warrior.walk! end @health = warrior.health end end class Player def initialize @max_health = 20 @mid_health = @max_health/2 @last_health = @max_health end def movement(warrior) if warrior.feel.enemy? attacks(warrior) elsif warrior.feel.wall? warrior.pivot! elsif warrior.feel.captive? warrior.rescue! else warrior.walk! end end def attacks(warrior) if warrior.feel.enemy? warrior.attack! else warrior.walk! end end def diminishing_health(warrior) warrior.health < @last_health end def play_turn(warrior) if diminishing_health(warrior) and warrior.health <= @mid_health warrior.walk!(:backward) elsif diminishing_health(warrior) movement(warrior) elsif !diminishing_health(warrior) and warrior.health < @max_health warrior.rest! else movement(warrior) end @last_health = warrior.health end end
  • 17. Level 8 You hear the mumbling of wizards. Beware of their deadly wands! Good thing you found a bow. Use warrior.look to determine your surroundings, and warrior.shoot! to fire an arrow.
  • 18. Linear Solution: class Player def play_turn(warrior) @max_health = 20 @current_health = warrior.health @danger_health = 9 if warrior.feel.wall? warrior.pivot! elsif warrior.feel.captive? warrior.rescue! elsif warrior.look.find_all {|space| space.captive? }.size.to_i == 1 warrior.walk! elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 2 warrior.shoot! elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 3 warrior.shoot! elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 0 warrior.walk! elsif warrior.health < @danger_health and @current_health < @health warrior.walk!(:backward) else warrior.shoot! end @health = warrior.health end end
  • 19. class Player def initialize @max_health = 20 @mid_health = @max_health/2 @last_health = @max_health end OOP Solution: def get_enemies(warrior) find_enemies(warrior) or find_enemies(warrior, :backward) end def movement(warrior) if get_captives(warrior) rescues(warrior) elsif get_enemies(warrior) attacks(warrior) elsif warrior.feel.wall? warrior.pivot! else warrior.walk! end end def find_enemies(warrior, where = :forward) enemy_spaces = warrior.look(where).find_all {|space| space.enemy? } def attacks(warrior) return enemy_spaces.any? if warrior.feel.enemy? end warrior.attack! elsif find_enemies(warrior) def get_captives(warrior) warrior.shoot! find_captives(warrior) or find_captives(warrior, :backward) end end end def find_captives(warrior, where = :forward) captive_spaces = warrior.look(where).find_all {|space| space.captive? } def diminishing_health(warrior) warrior.health < @last_health return captive_spaces.any? end end def rescues(warrior) if warrior.feel.captive? warrior.rescue! else warrior.walk! end end def play_turn(warrior) if diminishing_health(warrior) and warrior.health <= @mid_health warrior.walk!(:backward) elsif diminishing_health(warrior) movement(warrior) elsif !diminishing_health(warrior) and warrior.health < @max_health warrior.rest! elsif warrior.feel.captive? warrior.rescue! else movement(warrior) end @last_health = warrior.health end end
  • 20. Level 9 Time to hone your skills and apply all of the abilities that you have learned. Watch your back.
  • 21. Linear Solution: class Player def play_turn(warrior) @max_health = 20 @current_health = warrior.health @mid_health = 9 @danger_health = 3 if warrior.feel.wall? warrior.pivot! elsif warrior.feel.captive? warrior.rescue! elsif warrior.look(:backward).find_all {|space| space.enemy? }.size.to_i == 1 warrior.shoot!(:backward) elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 2 warrior.shoot! elsif warrior.health == @max_health warrior.walk! elsif warrior.look.find_all {|space| space.enemy? }.size.to_i == 0 and @current_health >= @health warrior.rest! elsif warrior.health < @mid_health and @current_health < @health warrior.walk!(:backward) else warrior.shoot! end @health = warrior.health end end
  • 22. OOP Solution: class Player def initialize @max_health = 20 @mid_health = @max_health/2 @danger_health = @max_health * 3 / 4 @last_health = @max_health end def rescues(warrior) if warrior.feel.captive? warrior.rescue! else warrior.walk! end end def get_enemies(warrior) find_enemies(warrior) or find_enemies(warrior, :backward) end def movement(warrior) if get_captives(warrior) rescues(warrior) elsif get_enemies(warrior) attacks(warrior) elsif warrior.feel.wall? warrior.pivot! else warrior.walk! end end def find_enemies(warrior, where = :forward) enemy_spaces = warrior.look(where).find_all {|space| space.enemy? } return enemy_spaces.any? end def get_captives(warrior) find_captives(warrior) or find_captives(warrior, :backward) end def find_captives(warrior, where = :forward) captive_spaces = warrior.look(where).find_all {|space| space.captive? } return captive_spaces.any? end def attacks(warrior) if warrior.feel(:backward).enemy? warrior.pivot! elsif warrior.feel.enemy? warrior.attack! elsif find_enemies(warrior, :backward) warrior.shoot!(:backward) elsif find_enemies(warrior) warrior.shoot! end end def diminishing_health(warrior) warrior.health < @last_health end def play_turn(warrior) if diminishing_health(warrior) and warrior.health <= @mid_health warrior.walk!(:backward) elsif diminishing_health(warrior) movement(warrior) elsif !diminishing_health(warrior) and warrior.health < @max_health warrior.rest! elsif warrior.feel.captive? warrior.rescue! else movement(warrior) end @last_health = warrior.health end end