There is a project to disassemble the Pokemon games at https://github.com/pret. As a reference in Pokemon red, You can find the file that defines the trainer AI here https://github.com/pret/pokered/blob/master/engine/battle/trainer_ai.asm

Unfortunately this is all in assembly and I don't believe there is a translation to C at this stage.