How Do I Detect Swamps in Screeps

Solution 1:

You can use Room.lookForAt method:

var terrain = creep.room.lookForAt('terrain', creep.pos.x+1, creep.pos.y);
if(terrain != 'swamp') {
  creep.move(RIGHT);
}

If you want to find all terrain tiles from the entire room, check this SO question.