SlideShare una empresa de 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

Más contenido relacionado

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

Destacado

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
 

Destacado (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