beginner – (Haskell) Two player random number guessing game

I’ve created a two-player number guessing game in Haskell. My main objective was to practice dealing with “state” in a purely functional language (such as player scores, whose turn it is, etc.)

Here are the rules:

Gameplay:

Two players will take turns guessing a random number between 1 and 10. Answers will be typed into the command line

Scoring:

If a player guesses the number correctly, they will be awarded 5 points
If a player is within two (inclusive) from the answer, the player will be awarded 3 points.
If a player is within three (inclusive) from the answer, they will be awarded 1 point
If a player is 7 or more points off, they will lose a point. The score may not be negative.
All other offsets will result in zero points
The game will continue until the one of the players reach 10 points

Caveats:

(1) This is was not designed to be an exercise in enjoyable game design — obviously the optimal solution is to always choose five, which doesn’t make for a lot of excitement 😀
(2) I am aware that Control.Monad.State exists, but I want to practice tracking state without it
(3) I know that the “mutual recursion” is difficult to follow. I would love some suggestions for getting rid of that which do not involve nesting if statements

import Data.Char
import System.Random

main = do
    stdGen <- getStdGen
    play 0 0 P1 stdGen

play :: Int -> Int -> Player -> StdGen -> IO ()
play p1Score p2Score player stdGen
    | p1Score < 10 && p2Score < 10 = continueGame p1Score p2Score player stdGen
    | otherwise = putStrLn $ show (determineWinner p1Score p2Score) ++ " wins!"

continueGame :: Int -> Int -> Player -> StdGen -> IO ()
continueGame p1Score p2Score player stdGen = do
    putStr $ show player ++ "'s turn. Pick a number between 1 and 10: "
    chosenNumber <- getLine
    if isInteger chosenNumber
        then do
            let (randomNumber, newGen) = randomR (1, 10) stdGen :: (Int, StdGen)
            putStrLn $ "The answer is " ++ show randomNumber

            let pointsEarned = calcPointsEarned randomNumber (read chosenNumber)
            let newP1Score = min (max (p1Score + calcPointsEarnedForPlayer player P1 pointsEarned) 0) 10
            let newP2Score = min (max (p2Score + calcPointsEarnedForPlayer player P2 pointsEarned) 0) 10

            putStrLn $ "P1 Score: " ++ show newP1Score
            putStrLn $ "P2 Score: " ++ show newP2Score

            play newP1Score newP2Score (changeTurn player) newGen
        else do
            putStrLn "The input must be an integer"
            play p1Score p2Score player stdGen

data Player = P1 | P2 deriving (Show, Eq)

isInteger :: String -> Bool
isInteger = and . map isNumber

changeTurn :: Player -> Player
changeTurn player 
    | player == P1 = P2
    | otherwise = P1

calcPointsEarned :: Int -> Int -> Int
calcPointsEarned actualAnswer chosenAnswer
    | offset == 0 = 5
    | offset <= 2 = 3
    | offset <= 3 = 1
    | offset >= 7 = (-1)
    | otherwise = 0
    where offset = abs $ chosenAnswer - actualAnswer

calcPointsEarnedForPlayer :: Player -> Player -> Int -> Int
calcPointsEarnedForPlayer actualTurn player pointsEarned 
    | actualTurn == player = pointsEarned
    | otherwise = 0

determineWinner :: Int -> Int -> Player
determineWinner p1Score p2Score
    | p1Score > p2Score = P1
    | otherwise = P2
```

unity – Moving player to the each enemies if enemies triggers with collider of range bar

I’m newbie in unity. I’m trying to learn it and i’m making a simple 2d game. In the picture red dots are enemies and blue one is range bar. All of them have colliders. Range bar is rotating around player. When GetMouseButtonDown(0), range bar stops and if range bar triggers with enemie or enemies, player will move towards each enemies one by one. I want to make an array which enemies triggers with range bar and make player move towards that enemie or enemies. But i couldn’t. I made a but i could not reach elements of that list from other script. Please help me 🙇🏻‍♂️.
enter image description here

unity – Why does the player grab the object outside the trigger zone?

I want the player to be able to grab an object (in this case the knife) when he is in the object’s trigger zone. He can get the knife but there is a problem: if I press grab button outside of the trigger zone, then he can get the knife immediately after entering the zone. I want Unity to get the input only when the player is in the trigger, otherwise it should not be working.

Here’s the grab script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Grab : MonoBehaviour
{
    public GameObject player;
    private bool grabbed;

    void Update()
    {
        if (Input.GetButtonDown("Grab"))
        {
            grabbed = true;
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject == Player.Instance.gameObject && grabbed)
        {
            gameObject.transform.SetParent(player.transform);
        }
    }
}

enter image description here

java – Get Meshes/Objects around Player

I have my PlayerObject and my GameObjects/Meshes, all with Colliders but iterating over every other Object and checking doesn’t seem optimal to me, so I am trying to only iterate over those around the Player but I just can’t seem to find a way to actually code it.

I also checked for Tutorials for it on YouTube etc., but either they’re extremely outdated or don’t explain it well enough for me to understand.

Any Information or snippets I could use?

unity – Why does Animator component prevent the player from facing left?

I’m making a 2D platformer with Unity. A few days ago, I was testing the game; the player could face right and left based on its moving direction and animations were playing correctly. I exited playmode because I had to assign the player position into a slot in inspector for the checkpoints. After assigning that, I entered the playmode again and surprisingly, I encountered a strange problem. The animations were working but the player was not able to face left when it was moving to the left side. I still have this problem. This is very strange to me because I didn’t change anything neither from the code nor the inspector. So I believe this is a random Unity bug. After testing the game many times, I found out these:

  1. If I disable Animator component, the player can flip again but obviously the animations won’t play.
  2. I can have both Animator and flipping working at the same time only when I check or uncheck root motion in playmode. But when I exit, the problem returns. So the previous unchecked or checked root motion will not work in the next playtest, so I can just check or uncheck it while the game is playing; otherwise it won’t work.

These are the reasons why I think the Animator component prevents the player from flipping but I have no idea why this is happening because this component has nothing to do with the facing code. Thanks in advance.

This is the code I use for flipping the protagonist:

bool isFacingLeft;

void Update()
    {
        //Move the player.
        //Target velocity is defined in another script and is not important in this context.
        targetVelocity = new Vector2(Input.GetAxis("Horizontal") * maxSpeed, 0);
       
       //Flip the player's localScale.x if the move speed is greater than .01 or less than -.01.
       if (isFacingLeft == true)
       {
          transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x) * -1, transform.localScale.y);
       }
       else
       {
          transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
       }

       if (targetVelocity != Vector2.zero)
          isFacingLeft = targetVelocity.x < 0 ? true : false;
    }

unity – Mirror Create Player From Client and Change Scene

You will need a custom NetworkManager and just handle the spawning/ setting there. But keep in mind if you trust the client with the players data, it is open to manipulation.

public class BasicNetwork: NetworkManager
{            
    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        Transform startPos = GetStartPosition();
        GameObject player = startPos != null
            ? Instantiate(playerPrefab, startPos.position, startPos.rotation)
            : Instantiate(playerPrefab);
        player.GetComponent<Player>().playerName = "Player " + Random.Range(0, 1000);
        //Gives the client authority
        NetworkServer.AddPlayerForConnection(conn, player);
    }
}

In the Room Example from Mirror you can find another example for passing data from the Roomplayer to the Player located in the OnRoomServerSceneLoadedForPlayer (which could be used if I understand your question correctly). Your RoomPlayer is like a Lobby and you could make a custom loading from your local clients data there – even if it is like a 1 Personlobby to get ready.

dnd 5e – How do I help a player terrified of their character dying in combat?

Call them on their bull****

D&D is a game about heroic characters risking their lives several times a day, I personally always play characters who want to survive, and will concentrate on staying alive, but there is a difference between being cautious and spoiling the game by not participating in combat encounters with the rest of the players.

I would say that there is a place for that style of play, but clearly not in your game, so you just need to tell them to knock it off.

I don’t suggest handing out items to make their life easier, or making up new rules, or anything to gently ‘encourage’ them. This player has made a commitment to play a game with other people and their responsibility is to participate with the rest of the players. Remind them of that.

Maybe this player just doesn’t like the style of game you play, and would prefer if everyone else ran away and was far more cautious too, but the quicker you identify that the quicker you can get on the same page – even if that page doesn’t include your player who refuses to join in.

You can then help them build the right character for them

As an example I currently play a wizard with 19 AC, a druid with 19 AC, a paladin with 21 AC and a monk with 22 AC. Both the wizard and paladin have access to the shield spell, my paladin prefers shield to smite, and my monk has defensive dualist taking his AC to a potential 27! My casters will stay at the back, use spells to increase defence, hide behind trees and keep out of line of sight, but they don’t run away. My paladin will use his slots to stay alive rather than dishing out damage, but will put himself in front of the squishy characters. My monk will look for the easiest targets to stun and let the barbarian take the damage, but all of them contribute.

This is active defence. Running away is not.

Rogues are notoriously squishy, especially if they are melee for some crazy reason, this probably doesn’t help your player feel very safe because everything hits them. You could help create them a character who won’t be so vulnerable after the conversation about participation.

unity – Why when playing mixamo animation on my player the player ending and also while playing the animation inside the ground(terrain)?

The player have this components : Animator , Rigidbody , Capsule Collider , Third Person User Control , Third Person Character.

I just downloaded mixamo animation for my character player.
In my Animator controller I added a new state and dragged in the animation.

Without the animation the player is standing fine. but with the animation the player is inside the ground.

The player is in the ground

The player animator controller settings in the inspector

The new state in the animator controller settings

The animation Rig tab settings --- I had to change it to be Humanoid to make the animation to be working correctly :

dungeon world – So what do I do when a player gets bad luck at the start of the session?

To answer ‘what should I do?’, the answer is probably:

Ask the player if they had a good time. Ask them if they enjoyed the story. If the answer is “yes”, then you did everything right.

To answer ‘how to make the encounter easy’, the Dungeon World answer is: you don’t.

It’s not your job to make encounters easy or hard. It’s your job to be a fan of the characters, and it’s your job to fill their lives with adventure. These are your agendas, and it sounds like you followed them perfectly well.

If players have bad luck, that just means you’ll be in the “The hero is being challenged and is failing” part of the story, and it means they’ll earn XP and grow and come back stronger in the end. It’s not a problem at all (assuming the player is having fun)

Remember that Lord of the Rings features the early part where Frodo gets stabbed by a Ring Wraith and then needs to be saved by Aragorn, and then almost dies, and then needs to be saved again when traveling to the safety of Rivendell and then again by Elrond’s healing. I don’t think anybody considers it a bad story because the first encounter wasn’t easy.

online roleplaying – Was I right to leave my rp group after feeling like my player agency was violated?

I was apart of a discord RP group, but I recently left after this incident. To give some background, I was being repeatedly belittled out of character by other members, and was being made to walk on egg shells around everyone. I was already a bit on edge the whole time I had been apart of this group, which was for around six months. So this event starts and we find this group of nineteen children who had survived a horrific attack. They end up being affected by some unknown disease so we are all in quarantine with them.

This whole time my Character gravitates to this one little girl and makes sure to dote on her. Several of the children, including her, are confirmed to be orphans. My character is in her 30s and I thought I would be given the chance to adopt her. Well the GM barely roleplayed as her because they could not handle dealing with multiple players and scenes very well. They gave us permission to just NPC the children to an extent because they can’t keep up. So I am just writing scene after scene the whole time of cuteness. I am ignored by most the players and the GM even when I try to interact with others, but I just play it off and try not to let it bother me.

So after the event ends, the GM announces that the particular little girl I was taking care of was adopted by another player who hadn’t even met her. Needless to say I was very livid. I ended up leaving because I felt like no one was taking me into consideration or even allowing me to really interact with the events. Two players reached out to me to try and get me to come back even though in there own words the mods were “Cold hearted.” I didn’t talk to the GMs about it because I was so mad and hurt to be stepped on like that, nor did they ever try to reach out to me. Am I just being childish here or am I in the right?