Showing posts with label Algorithm. Show all posts
Showing posts with label Algorithm. Show all posts

Tuesday, 15 October 2013

Proximity detection

1.
Problem:  The players proximity to the bomb needs to be detected
Inputs:  playerLocX, playerLocY, bombX, bombY
Outputs:  Color.colour of oval graphic

Processing:  All players
if playerLocX > bombX - 20
and
playerLocX < bombX + 20
and
playerLocY > bombY - 20
and
playerLocY < bombY + 20
then
change graphic set colour
draw oval

Pseudocode
Players proximity to bomb

Get playerLocX, playerLocY, bombX, bombY

if playerLocX > bombX - 20
and
playerLocX < bombX + 20
and
playerLocY > bombY - 20
and
playerLocY < bombY + 20
then
change graphic set colour
draw oval
else
end

2.
Problem:  The players proximity to other players needs to be detected
Inputs:  playerLocX, playerLocY
Outputs:  Color.colour of graphic oval
Processing:  All players
if playerLocX > playerLocX - 20
and
playerLocX < playerLocX + 20
and
playerLocY > playerLocY - 20
and
playerLocY < playerLocY + 20
then
change graphic set color
draw oval

Pseudocode
Players proximity to other players

Get playerLocX, playerLocY

if playerLocX > playerLocX - 20
and
playerLocX < playerLocX + 20
and
playerLocY > playerLocY - 20
and
playerLocY < playerLocY + 20
then
change graphic set color
draw oval
else
end

Tuesday, 3 September 2013

Update environment variables 2 - implementation


Update environment variables 2 - algorithm

1.  The problem is that the environment variables need to be calculated.
2.  The inputs of this algorithm are X, Y and R.
3.  The outputs of this algorithm are X and Y.
4.  The processing tasks are Y incremented by R, If Y > 100 then X decremented by 10 and If Y > 200 then X and Y equal 0.
5.  Pseudocode

Update environment variables 2
Prompt user for X, Y, R

Get X, Y, R

Y = Y + R
If Y > 100
X = X - 10
If Y > 200
X = 0
Y = 0

End

Monday, 26 August 2013

Update Environment Variables - algorithms

1. The problem is that the environment variables need to be calculated to be updated.
2. The inputs are X, Y, R and T.
3. The outputs are X and Y.
4. The processing tasks are X incremented by R and Y incremented by T.
If X > 5000 then Y decremented by 1000.
If Y < 0, Y and X are set to 0.
5. Pseudocode

Update environment variables
Prompt user for X, Y, R and T

Get X, Y, R and T
X = X + R
Y = Y + T

If X > 5000
Y = Y - 1000

If Y < 0
Y = 0
X = 0

End


Tuesday, 13 August 2013

Switch flowchart


Switch

Switch Month
Case condition 1
Display "The number is 1"

Case condition 2
Display "The number is 2"

Case condition 3
Display "The number is 3"

Case condition 4
Display "The number is 4"

Case condition 5
Display "The number is 5"

Case condition 6
Display "The number is 6"

Case condition 7
Display "The number is 7"

Case condition 8
Display "The number is 8"

Case condition 9
Display "The number is 9"

Case condition 10
Display "The number is 10"

Case condition 11
Display "The number is 11"

Case condition 12
Display "The number is 12"

Case Else
Prompt user to re-enter value

End Select

And

The value that needs to be stored in Number to display the message "This number does not meet the condition" are 7 or less or 11 or higher.

Monday, 12 August 2013

Or

The numbers 5, 6, 7 and 8 would need to be stored in Number to make the program display the message "This number does not meet the condition".

Validation and error trapping

1. 
Pseudocode
Calculate price of sending parcel
Prompt user for ItemWeight, CostPerKilo
Get ItemWeight, CostPerKilo

If ItemWeight is a number and CostPerKilo is a number
 
CostofSendingParcel = ItemWeight * CostPerKilo
If CostofSendingParcel < 100
Display CostofSendingParcel
Else
CostAfterDiscount = CostofSendingParcel * 0.9
Display CostAfterDiscount
End If

Else Display ErrorMessage
 
End
2.
 

Tuesday, 6 August 2013

Apply Discount

 
Apply discount algorithm
 
Defining the problem:
The problem is that we need to find the cost of sending a parcel to someone and calculating the discount if the cost is more than $100.
 
Defining the inputs:
The inputs are; ItemWeight, CostPerKilo
 
Defining the outputs:
The outputs are; CostofSendingParcel, CostAfterDiscount
 
Define the processing:
1.  Get the item weight
2.  Get the cost per kilo
3.  Calculate the cost of sending a parcel
4.  If the cost of sending a parcel is less than $100, display the cost of sending a parcel
5.  Else, apply a 10% discount
6.  Display the cost after discount
 
Pseudocode
Calculate price of sending parcel
Prompt user for ItemWeight, CostPerKilo
 
Get ItemWeight, CostPerKilo
 
CostofSendingParcel = ItemWeight * CostPerKilo
 
If CostofSendingParcel < 100
Display CostofSendingParcel
Else
CostAfterDiscount = CostofSendingParcel * 0.9
Display CostAfterDiscount
End If
End

Monday, 5 August 2013

Flowchart 1



Send a parcel algorithm

Task 1
1.  The problem is that we need to find the price of sending a parcel.
2.  The inputs are the weight of the parcel and the price per kiloram.
3.  The output is the final cost of sending the parcel.
4.
i) Get the items weight
ii) Get the standard charge per kilo
iii) Calculate the price of sending the item
iv) Display the price of sending the item
5.  Pseudocode
Calculate price of sending parcel

Prompt user for ItemWeight, CostPerKilo
Get ItemWeight, CostPerKilo
CostofSendingParcel = ItemWeight*CostPerKilo
Display CostofSendingParcel

Task 2
The steps ti creating an algorithm are:
Step 1: Define the problem
Step 2: Define the inputs
Step 3: Define the outputs
Step 4: Define processing
Step 5: Write the pseudocode

Tuesday, 18 June 2013

Simple WoW stuff

A character in WoW has 5 base character attributes:  strength, agility, stamina, intellect and spirit.

There are 7 calculated character statistics for each player.

The player stats are calculated based on the combination of the race and class, so that class bonus' are added on to base race attributes.

PlayerStats = BaseRaceAttributes + ClassEffects

The health of a character is calculated using the following equations: 
If Stamina is less than 20:

    Health = BaseHealth + (Stamina - 20)



If Stamina is greater than or equal to 20:

    Health = BaseHealth + 10 * (Stamina - 20)

The mana of a character is calculated using the following equations: 
If Intellect is less than 20:

    Mana = BaseMana + (Intellect - 20)



If Intellect is greater than or equal to 20:

    Mana = BaseMana + 15 * (Intellect - 20)

Calculated player mana algorithm
Calculated player health algorithm