Skip to main content
added 121 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
infile <- file("stdin")
open(infile)
repeat{
    input <- readLines(infile,1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
    }
    attack <- function(id,info){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(exists("memory")){
                dead <- memory$ID[memory$Status=="Dead"]
                                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                                        deadvet<-veteran[veteran$ID%in%dead,]
                    deadvet<-unlist(lapply(split(deadvet,deadvet$ID),function(x)tail(x$Attack,1)))
                    deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead]deadvet,levels=c("R","P","S","")))
                                        livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead]veteran$Attack,levels=c("R","P","S","")))-deadvet
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }
            }else{
                choice <- sample(c("S","P","R"),1)
                memory <- data.frame(ID=id, Status="Alive", Attack=choice)
            }
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id){
        if(exists("memory")){
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
        }else{
            memory <- data.frame(ID=id,Status="Alive",Attack="")
        }
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
            }
        }
        paste("K",id,sep="")
    }
    result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
    cat(result,"\n",sep="")
    flush(stdout())
}
infile <- file("stdin")
open(infile)
repeat{
    input <- readLines(infile,1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
    }
    attack <- function(id,info){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(exists("memory")){
                dead <- memory$ID[memory$Status=="Dead"]
                        veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                        if(nrow(veteran[!is.na(veteran[,1]),])>0){
                              deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                              livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }
            }else{
                choice <- sample(c("S","P","R"),1)
                memory <- data.frame(ID=id, Status="Alive", Attack=choice)
            }
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id){
        if(exists("memory")){
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
        }else{
            memory <- data.frame(ID=id,Status="Alive",Attack="")
        }
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
            }
        }
        paste("K",id,sep="")
    }
    result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
    cat(result,"\n",sep="")
    flush(stdout())
}
infile <- file("stdin")
open(infile)
repeat{
    input <- readLines(infile,1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
    }
    attack <- function(id,info){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(exists("memory")){
                dead <- memory$ID[memory$Status=="Dead"]
                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                    deadvet<-veteran[veteran$ID%in%dead,]
                    deadvet<-unlist(lapply(split(deadvet,deadvet$ID),function(x)tail(x$Attack,1)))
                    deadvet <- table(factor(deadvet,levels=c("R","P","S","")))
                    livevet <- table(factor(veteran$Attack,levels=c("R","P","S","")))-deadvet
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }
            }else{
                choice <- sample(c("S","P","R"),1)
                memory <- data.frame(ID=id, Status="Alive", Attack=choice)
            }
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id){
        if(exists("memory")){
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
        }else{
            memory <- data.frame(ID=id,Status="Alive",Attack="")
        }
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
            }
        }
        paste("K",id,sep="")
    }
    result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
    cat(result,"\n",sep="")
    flush(stdout())
}
added 4 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
infile <- file("stdin")
open(infile)
repeat{
    input <- readLines(infile,1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
    }
    attack <- function(id,info){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(exists("memory")){
                dead <- memory$ID[memory$Status=="Dead"]
                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                    deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                    livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }
            }else{
                choice <- sample(c("S","P","R"),1)
                memory <- data.frame(ID=id, Status="Alive", Attack=choice)
            }
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id){
        if(exists("memory")){
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
        }else{
            memory <- data.frame(ID=id,Status="Alive",Attack="")
        }
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
            }
        }
        paste("K",id,sep="")
    }
    result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
    cat(result,"\n",sep="")
    flush(stdout())
}
infile <- file("stdin")
open(infile)
repeat{
    input <- readLines(infile,1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
    }
    attack <- function(id,info){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(exists("memory")){
                dead <- memory$ID[memory$Status=="Dead"]
                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                    deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                    livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }
            }else{
                choice <- sample(c("S","P","R"),1)
                memory <- data.frame(ID=id, Status="Alive", Attack=choice)
            }
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id){
        if(exists("memory")){
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
        }else{
        memory <- data.frame(ID=id,Status="Alive",Attack="")
    }
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
            }
        }
        paste("K",id,sep="")
    }
    result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
    cat(result,"\n",sep="")
    flush(stdout())
}
infile <- file("stdin")
open(infile)
repeat{
    input <- readLines(infile,1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
    }
    attack <- function(id,info){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(exists("memory")){
                dead <- memory$ID[memory$Status=="Dead"]
                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                    deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                    livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }
            }else{
                choice <- sample(c("S","P","R"),1)
                memory <- data.frame(ID=id, Status="Alive", Attack=choice)
            }
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id){
        if(exists("memory")){
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
        }else{
            memory <- data.frame(ID=id,Status="Alive",Attack="")
        }
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
            }
        }
        paste("K",id,sep="")
    }
    result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
    cat(result,"\n",sep="")
    flush(stdout())
}
added 133 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47

Yet untested (i am very unfamiliar with the java machinery).
TheThe idea of this wolf pack is that it keeps in memory (in a file called collective_memory.txt) who's alive or dead, check what the dead wolves and the alive wolves used as attacks and change the choice probability accordingly.

infile <- file("stdin")
open(infile)
repeat{
        input <- readLines(file("stdin")infile,1)
        type <- substr(input,1,1)
        id <- substr(input,2,3)
    f <- "collective_memory.txt"
        if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL}
      }
     attack <- function(id,info,f){
                if(info%in%c("B","L")){choice <- "S"}
                if(info=="S"){choice <- "P"}
                if(info=="W"){
                        if(file.exists(f"memory")){
                memory <- read.table(f,sep="\t",header=TRUE)
                                dead <- memory$ID[memory$Status=="Dead"]
                                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                                        deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                                        livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                                        probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                                        probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                                        probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                                        choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                                        memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                                }else{
                                        choice <- sample(c("S","P","R"),1)
                                        memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                                    }
                            }else{
                                    choice <- sample(c("S","P","R"),1)
                                    memory <- data.frame(ID=id, Status="Alive", Attack=choice)
                                }
                write.table(memory,file=f,sep="\t",row.names=FALSE, col.names=TRUE)
                }
                paste(choice,id,sep="")
        }
        move <- function(id,info){
                choice <- "H"
                paste(choice,id,sep="")
        }
        initialize <- function(id,f){
                if(file.exists(f"memory")){
            memory <- read.table(f,sep="\t",header=TRUE)
                        memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
              }else{
        }else{  memory <- data.frame(ID=id,Status="Alive",Attack="")}
    }
           confirmed_dead <- memory$ID[memory$Status=="Dead"]
                last_seen <- memory[!memory$ID%in%confirmed_dead,]
                last_seen <- last_seen[last_seen$Attack=="",]
                lid <- table(last_seen$ID)
                turns <- max(lid)
                dead <- lid[lid<(turns-1)]
                if(length(dead)>0){
                        dead_id <- names(dead)
                        for(i in dead_id){
                                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
                            }
                    }
        write.table(memory,file=f,sep="\t",row.names=FALSE, col.names=TRUE)
                paste("K",id,sep="")
            }
        result <- switch(type,"A"=attack(id,info,f),"M"= move(id,info),"S"=initialize(id,f))
        cat(result,"\n",sep="")
        flush(stdout())
    }

Yet untested (i am very unfamiliar with the java machinery).
The idea of this wolf pack is that it keeps in memory (in a file called collective_memory.txt) who's alive or dead, check what the dead wolves and the alive wolves used as attacks and change the choice probability accordingly.

repeat{
    input <- readLines(file("stdin"),1)
    type <- substr(input,1,1)
    id <- substr(input,2,3)
    f <- "collective_memory.txt"
    if(nchar(input)>3){info <- substr(input,4,nchar(input))}else{info <- NULL}
    attack <- function(id,info,f){
        if(info%in%c("B","L")){choice <- "S"}
        if(info=="S"){choice <- "P"}
        if(info=="W"){
            if(file.exists(f)){
                memory <- read.table(f,sep="\t",header=TRUE)
                dead <- memory$ID[memory$Status=="Dead"]
                veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                if(nrow(veteran[!is.na(veteran[,1]),])>0){
                    deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                    livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                    probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                    probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                    probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                    choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                    }
                }else{
                    choice <- sample(c("S","P","R"),1)
                    memory <- data.frame(ID=id, Status="Alive", Attack=choice)
                    }
                write.table(memory,file=f,sep="\t",row.names=FALSE, col.names=TRUE)
        }
        paste(choice,id,sep="")
    }
    move <- function(id,info){
        choice <- "H"
        paste(choice,id,sep="")
    }
    initialize <- function(id,f){
        if(file.exists(f)){
            memory <- read.table(f,sep="\t",header=TRUE)
            memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
            }else{memory <- data.frame(ID=id,Status="Alive",Attack="")}
        confirmed_dead <- memory$ID[memory$Status=="Dead"]
        last_seen <- memory[!memory$ID%in%confirmed_dead,]
        last_seen <- last_seen[last_seen$Attack=="",]
        lid <- table(last_seen$ID)
        turns <- max(lid)
        dead <- lid[lid<(turns-1)]
        if(length(dead)>0){
            dead_id <- names(dead)
            for(i in dead_id){
                memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
                }
            }
        write.table(memory,file=f,sep="\t",row.names=FALSE, col.names=TRUE)
        paste("K",id,sep="")
        }
    result <- switch(type,"A"=attack(id,info,f),"M"= move(id,info),"S"=initialize(id,f))
    cat(result,"\n",sep="")
    flush(stdout())
    }

The idea of this wolf pack is that it keeps in memory who's alive or dead, check what the dead wolves and the alive wolves used as attacks and change the choice probability accordingly.

infile <- file("stdin")
open(infile)
repeat{
      input <- readLines(infile,1)
      type <- substr(input,1,1)
      id <- substr(input,2,3)
      if(nchar(input)>3){
        info <- substr(input,4,nchar(input))
    }else{
        info <- NULL
      }
     attack <- function(id,info){
            if(info%in%c("B","L")){choice <- "S"}
            if(info=="S"){choice <- "P"}
            if(info=="W"){
                  if(exists("memory")){
                        dead <- memory$ID[memory$Status=="Dead"]
                        veteran <- memory[memory$Attack!="" & !is.na(memory$Attack), ]
                        if(nrow(veteran[!is.na(veteran[,1]),])>0){
                              deadvet <- table(factor(veteran$Attack[veteran$ID%in%dead],levels=c("R","P","S","")))
                              livevet <- table(factor(veteran$Attack[!veteran$ID%in%dead],levels=c("R","P","S","")))
                              probR <- (1+livevet['R'])/(1+livevet['R']+deadvet['R'])
                              probS <- (1+livevet['S'])/(1+livevet['S']+deadvet['S'])
                              probP <- (1+livevet['P'])/(1+livevet['P']+deadvet['P'])
                              choice <- sample(c("S","P","R"),1,prob=c(probS,probP,probR))
                              memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                        }else{
                              choice <- sample(c("S","P","R"),1)
                              memory <- rbind(memory, data.frame(ID=id, Status="Alive", Attack=choice))
                        }
                  }else{
                        choice <- sample(c("S","P","R"),1)
                        memory <- data.frame(ID=id, Status="Alive", Attack=choice)
                  }
            }
            paste(choice,id,sep="")
      }
      move <- function(id,info){
            choice <- "H"
            paste(choice,id,sep="")
      }
      initialize <- function(id){
            if(exists("memory")){
                  memory <- rbind(memory,data.frame(ID=id,Status="Alive",Attack=""))
            }else{
          memory <- data.frame(ID=id,Status="Alive",Attack="")
    }
           confirmed_dead <- memory$ID[memory$Status=="Dead"]
            last_seen <- memory[!memory$ID%in%confirmed_dead,]
            last_seen <- last_seen[last_seen$Attack=="",]
            lid <- table(last_seen$ID)
            turns <- max(lid)
            dead <- lid[lid<(turns-1)]
            if(length(dead)>0){
                  dead_id <- names(dead)
                  for(i in dead_id){
                        memory <- rbind(memory, data.frame(ID=i, Status="Dead", Attack=""))
                  }
            }
            paste("K",id,sep="")
      }
      result <- switch(type,"A"=attack(id,info),"M"= move(id,info),"S"=initialize(id))
      cat(result,"\n",sep="")
      flush(stdout())
}
added 1 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
Loading
added 195 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
Loading
added 1 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
Loading
deleted 510 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
Loading
added 36 characters in body
Source Link
plannapus
  • 9k
  • 22
  • 47
Loading
Source Link
plannapus
  • 9k
  • 22
  • 47
Loading