{"id":28,"date":"2025-12-24T16:57:04","date_gmt":"2025-12-24T09:57:04","guid":{"rendered":"https:\/\/medytic.blog\/?p=28"},"modified":"2026-01-31T09:51:28","modified_gmt":"2026-01-31T02:51:28","slug":"project-rock-paper-scissors-game","status":"publish","type":"post","link":"https:\/\/medytic.blog\/th\/2025\/12\/24\/project-rock-paper-scissors-game\/","title":{"rendered":"Project: \u0e40\u0e01\u0e21 \u0e40\u0e1b\u0e48\u0e32-\u0e22\u0e34\u0e49\u0e07-\u0e09\u0e38\u0e1a \u0e14\u0e49\u0e27\u0e22\u0e20\u0e32\u0e29\u0e32 R"},"content":{"rendered":"<p class=\"wp-block-paragraph\">This is a Rock Paper Scissors game I built in R!  This project was actually an exercise from a data analysis course I enrolled. It was a fun way to practice the logic of coding<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to play<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To play this game, you will need to run the code in an R environment. You can use any platform you are comfortable with, e.g. <a href=\"https:\/\/posit.co\/\">Posit Cloud<\/a>, Google Colab, or RStudio Desktop. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Follow these steps<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Copy the code below, or from <a href=\"https:\/\/gist.github.com\/eettirk\/46e367ff32d8502cadbdc0b2c02b59df\">GitHub<\/a>.<\/li>\n\n\n\n<li>Paste and run the script in your R console.<\/li>\n\n\n\n<li>Start the game by typing <code>play_rps()<\/code> and hitting Enter.<\/li>\n\n\n\n<li>Follow the on-screen instructions to make your move.<\/li>\n<\/ol>\n\n\n<div class=\"alignwide wp-block-code\">\n\t<div class=\"cm-editor\">\n\t\t<div class=\"cm-scroller\">\n\t\t\t\n<pre>\n<code><div class=\"cm-line\">play_rps &lt;- function() {<\/div><div class=\"cm-line\">  hands &lt;- c(&quot;rock&quot;, &quot;paper&quot;, &quot;scissors&quot;)<\/div><div class=\"cm-line\">  player_score &lt;- 0<\/div><div class=\"cm-line\">  valid_choices &lt;- c(hands, &quot;exit&quot;)<\/div><div class=\"cm-line\">  while(TRUE) {<\/div><div class=\"cm-line\">    player_choice &lt;- tolower(readline(&quot;Choose your hand(rock, paper, scissors) or exit: &quot;))<\/div><div class=\"cm-line\">    <\/div><div class=\"cm-line\">    # Check for invalid inputs <\/div><div class=\"cm-line\">    if (!(player_choice %in% valid_choices)) {<\/div><div class=\"cm-line\">      print(&quot;Invalid choice. Please enter &apos;rock&apos;, &apos;paper&apos;, &apos;scissors&apos;, or &apos;exit&apos;.&quot;)<\/div><div class=\"cm-line\">      next # Skips the rest of the loop and starts the next iteration<\/div><div class=\"cm-line\">    }<\/div><div class=\"cm-line\">    <\/div><div class=\"cm-line\">    if (player_choice == &quot;exit&quot;) {<\/div><div class=\"cm-line\">      cat(&quot;\\n--- GAME OVER ---\\n&quot;)<\/div><div class=\"cm-line\">      print(paste(&quot;Total score: &quot;,player_score))<\/div><div class=\"cm-line\">      break<\/div><div class=\"cm-line\">    }<\/div><div class=\"cm-line\">    com_choice &lt;- sample(hands, 1)<\/div><div class=\"cm-line\">    print(paste(&quot;Computer chose:&quot;, com_choice))<\/div><div class=\"cm-line\">    <\/div><div class=\"cm-line\">    if((player_choice == &quot;rock&quot; &amp; com_choice == &quot;scissors&quot;)|<\/div><div class=\"cm-line\">            (player_choice == &quot;paper&quot; &amp; com_choice == &quot;rock&quot;)|<\/div><div class=\"cm-line\">            (player_choice == &quot;scissors&quot; &amp; com_choice == &quot;paper&quot;)) {<\/div><div class=\"cm-line\">      player_score &lt;- player_score+1<\/div><div class=\"cm-line\">      cat(&quot;you win this round!&quot;)<\/div><div class=\"cm-line\">    }<\/div><div class=\"cm-line\">    else if((player_choice == &quot;rock&quot; &amp; com_choice == &quot;paper&quot;)|<\/div><div class=\"cm-line\">            (player_choice == &quot;paper&quot; &amp; com_choice == &quot;scissors&quot;)|<\/div><div class=\"cm-line\">            (player_choice == &quot;scissors&quot; &amp; com_choice == &quot;rock&quot;)) {<\/div><div class=\"cm-line\">      cat(&quot;you lose this round!&quot;)<\/div><div class=\"cm-line\">    }<\/div><div class=\"cm-line\">    else {<\/div><div class=\"cm-line\">      cat(&quot;It&apos;s a draw&quot;)<\/div><div class=\"cm-line\">    }<\/div><div class=\"cm-line\">    print(paste(&quot;Current Score:&quot;, player_score))<\/div><div class=\"cm-line\">  }<\/div><div class=\"cm-line\">}<\/div><\/code><\/pre>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">I hope you enjoy!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>","protected":false},"excerpt":{"rendered":"<p>This is a Rock Paper Scissors game I built in R! This project was actually an exercise from a data analysis course I enrolled. It was a fun way to practice the logic of coding How to play To play this game, you will need to run the code in an R environment. You can [&hellip;]<\/p>\n","protected":false},"author":273023487,"featured_media":35,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_seo_schema_type":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[10189],"tags":[231379255],"class_list":["post-28","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-r"],"jetpack_publicize_connections":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgTbA2-s","jetpack-related-posts":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/medytic.blog\/wp-content\/uploads\/2025\/12\/pexels-photo-32778168.jpeg?fit=1880%2C1253&ssl=1","_links":{"self":[{"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/users\/273023487"}],"replies":[{"embeddable":true,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":13,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":167,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/posts\/28\/revisions\/167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/media\/35"}],"wp:attachment":[{"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/medytic.blog\/th\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}