lundi 1 mars 2021

disabling enemy, getting a random number, teleport to that number as a coordinate, enabling the enemy

i have been trying to create a wave game where enemies keeps re-spawning after i have killed them. i have created the enemy and a gun to kill them with. currently, i just disable the enemy object when it detects a collision with a bullet. and here comes the problem.

i want to get a random number and then teleport the enemy to that coordinate. and then re-enable the enemy so that it seems like it keeps re-spawning. how do i do that? is there a better solution? i am using c#.

i don't think i need to give pictures of my code, but if someone needs it to help me, then i will gladly give out some pictures. i am also a beginner to programming, so if its possible, then simple code is appreciated.




Reshuffling data and running multiple regressions

I am trying to replicate several studies that use the same longitudinal dataset. Observations are by individual-year, and individuals are nested within countries. I'm trying to demonstrate that there is selection bias. Namely, the primary iv (age) is positively associated with binary y only because countries that have more of y are more likely to select older individuals. I can't use an instrument or multilevel model for theoretical reasons.

One way I am trying to show this is by re-sampling the entry age across individuals within the same country. So the distribution of age roughly stays the same in each country, but the value now differs across individuals within that country.

I already know how to do this once. But what I need help with is how to do this resampling 100's of times AND run a logistic regression each time. I want to keep track of the coefficients and p-values for each regression in a data frame. Or somehow "pool" all of the coefficients and p-values into one. The idea here is that I want to show that even if you randomly shuffle the entry age of individuals within countries, you will still get the same result - a positive and significant association.

data:

set.seed(123)
library(dplyr)
n <- 50
df <- data.frame(country = rep(c("A", "B"), each = n), individual = rep(c(1:50, 51:100), each = 1))
df <- df %>%
  mutate(age = ifelse(country == "A", round(rnorm(n, 60,5)), round(rnorm(n, 30,5))))

df <- df[rep(row.names(df), sample(1:10, 100, replace = T)), 1:ncol(df)]

df <- df %>%
  group_by(individual) %>%
  mutate(age = age + seq(1:length(individual)),
         y = ifelse(country == "A", rbinom(n, 1, prob = .75), rbinom(n, 1, prob = .25))) %>%
  ungroup()

mod1 <- glm.cluster(df, y ~ age, cluster = "individual", family = binomial(link = "logit"))
summary(mod1)

In the original df sometimes the individual-year observation is duplicated for dv = 1 (if individual did y more than once in a year), but I am not sure how to recreate that in reproducible example. Although, I don't think it really matters when trying to reproduce what I am trying to do.

I can do the above reshuffle method once:

seednum <- sample(1:1000,1)
set.seed(seednum)

df1 <- df %>% distinct(individual, .keep_all = T)

df1 <- df1 %>%
  group_by(country) %>%
  mutate(age_random = sample(age, length(country)))

df1 <- df1[,c("individual", "age_random")]
df <- plyr::join(df, df1, by = "individual", match = "first")

df <- df %>%
  group_by(individual) %>%
  mutate(age_random = age_random + seq(1:length(individual))) %>%
  ungroup()

mod1 <- glm.cluster(df, y ~ age_random, cluster = "individual", family = binomial(link = "logit"))
summary(mod1)



For thermocode 4 expressed as 1010101. How can we selectively choose 1’s in thiis bit stream, or find positions of 1’s

If I have bitstream 1010101 . I want to store the locations if 1’s separately and then randomly select these 1’s




Return simulated pricing result

I am quite new to R and try to do a pricing simulation. The goal is to have a vector with length n, that gives a percentage for the coupon that will be received. When I use print, I get exactly the result I want. However, for my subsequent calculations I cannot proceed with results in print format. I tried replacing it with return but this just gives me one result.

Any input is appreciated.

(package used for rgpd is POT)

bond_coupon <- function(n, l) {
     events <- rpois(n, l) #simulates the rate of arrival according to a Poisson process
     for (i in 1:length(events)){
         cat <- rgpd(events[i], loc=1000, scale=100, shape=1) #simulates the severance of each event
         if(events[i]>1){
             coupon <- prod(1-((cat-1000)/cat))
         } else if(events[i]==1){
             coupon<- 1-((cat-1000)/cat)
         } else{
             coupon<- 1.00
         }
         print(coupon)
     }
 }



Select random field from database in Python

So I am developing a Django app and what I want at the moment in to develop a script that selects a random field from a row with 3 words in a MySQL database that I have. I have searched for info but haven't managed how to do it.

My database:

enter image description here

What I want is the script to read the database and select a random word each time. I haven't worked so much with DBs in Python so I have no clue about how to do it. Help is much appreciated.




arranging objects in random rows and columns

private void InitialSetup()
{
    AddPiece(whiteRook, white, 0, 0);
    AddPiece(whiteKnight, white,1,2);
    AddPiece(whiteBishop, white,2,0);
    AddPiece(whiteQueen, white, 3,4);
    AddPiece(whiteKing, white, 4, 6);
    AddPiece(whiteBishop, white,5,0);
    AddPiece(whiteKnight, white,6,3);
    AddPiece(whiteRook, white, 7, 6);
}

public void AddPiece(GameObject prefab, Player player, int col, int row)
{
    GameObject pieceObject = board.AddPiece(prefab, col, row);

    player.pieces.Add(pieceObject);
    pieces[col, row] = pieceObject;
}

8 columns 6 rows I have 48 game objects, I want them to be arranged in random rows and columns every time the game starts, but how can I do this with the addPiece method?




dimanche 28 février 2021

Python insert output into new row of existing excel file

I have this simple code to print random numbers. Each time i run this code, the values are being replaced. How do I make it write from the next available row within the same excel file? Thanks.

import pandas as pd
import random
import time
from xlsxwriter import*
from time import time, sleep


numberList = [0, 40, 43, 45, 48, 50, 53, 55, 58, 60]
my_list = []
my_list = (random.choices(numberList, weights=(2, 1, 3, 6, 3, 2, 2, 1, 1, 1), k=100))


df = pd.DataFrame.from_dict({'Random No':my_list})
df.to_excel('dataset5.xlsx', header=True, index=False)