Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:34:02+00:00 2026-05-30T08:34:02+00:00

I am currently working on a text based web game, where in I simulate

  • 0

I am currently working on a text based web game, where in I simulate the battle sequences automatically like MyBrute and Pockie Ninja

So this is the situation.

We have 2 Players with different attack speed

attack speed(determines the number of seconds needed for a player to start attacking)

(Easy Example) Lets assume Player 1 has 6s and Player 2 has 3s

This means Player 2 will attack twice before Player 1 does

(its because if two player tied on a attack turn, the one with the better attack speed goes first)

(but if they have the same attack speed, the player who have not attack lately will go)

Now my problem is in the loop.

I’d like to determine who’s turn it is with the minimum number of loops

for our Easy Example we could just create an infinite loop with a counter that increments 3 values to determine whos turn it’s going to be and just check if every iteration if we have a winner and exit the loop. (this is my algo you can suggest better one)

The big problem for me is when i have decimal values now for attack speed

Realistic Example (assume that i only use 1 digit for decimal)

Player1 attack speed = 5.7

Player2 attack speed = 6.6

at worst we could have is 0.1 as a an LCD and use as subtrahend per loop but i want to determine the the best subtrahend(LCD) value.

Hope it makes sense.

Thank you. I appreciate you sharing your great minds.

UPDATE
//THIS IS NOT THE ACTUAL CODES BUT THIS IS THE LOGIC

decimal Player1Turn = Player1.attackspeed;
decimal Player2Turn = Player2.attackspeed;
decimal LCD = GetLCD(Player1.attackspeed,Player2.attackspeed)  ***//THIS IS WHAT I WANT TO DETERMINE***
while (Player1.HP >0 && Player2.HP >0)
{
    Player1Turn -= LCD;
    Player2Turn -= LCD;
    if (Player1Turn<=0)
    {
        //DO STUFF
        Player1Turn = Player1.attackspeed;
    }
    if (Player2Turn<=0)
    {
        //DO STUFF
        Player2Turn = Player2.attackspeed;
    }
}

WE CAN USE A FUNCTION LIKE

public decimal GetLCD(decimal num1, decimal num2)
   {
        //returns the lcd  
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:34:03+00:00Added an answer on May 30, 2026 at 8:34 am

    The following code processes the battle sequence without using the lowest common denominator. It will also run about 1 million times faster than all possible attempts with using the lowest common denominator for player attack speeds equal e.g. 1000 and 1000.001 respectively.

    decimal time = 0;
    while (player1.HP > 0 && player2.HP > 0) {
        decimal player1remainingtime = player1.attackspeed - (time % player1.attackspeed);
        decimal player2remainingtime = player2.attackspeed - (time % player2.attackspeed);
        time += Math.Min(player1remainingtime, player2remainingtime);
        if(player1remainingtime < player2remainingtime) {
            //it is player 1 turn; do stuff;
        } else if(player1remainingtime > player2remainingtime) {
            //it is player 2 turn; do stuff;
        } else {
            //both player turns now
            if(player1.attackspeed < player2.attackspeed) {
                //player 1 is faster, its player 1 turn; do stuff
                //now do stuff for player 2
            } else {
                //player 2 is faster, its player 2 turn; do stuff
                //now do stuff for player 1
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a little text-based game after watching the new Tron movie
I'm currently working through some exercises in a c++ book, which uses text based
I'm currently working on a membership system for my web application, which is based
I'm working on a web app that currently has a table-based layout. Ideally I'd
I'm currently working on a programming assignment for school. It's a simple text-based RPG.
I'm currently working on a solution to automatically generate ExtJS forms based on a
I am currently working on a project and my goal is to locate text
I'm currently working on a jQuery script that will translate the site's text into
I have recently started using Vim as my text editor and am currently working
I need to write Hebrew text in Latex. I am currently working on Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.