public static void create_boxcar(Train train, GameObject boxcar)
 {
     // save the train on the board, but boxcar will overwrite it
     if (train.in_city) // if train is in city then add boxcars
     {
         Tilemap tilemap          = train.station_track.tilemap;
         Boxcar  boxcar_component = boxcar.GetComponent <Boxcar>();
         boxcar_counter += 1;
         boxcar_component.attach_to_train(train);
         MovingObject last_vehicle = train.get_last_vehicle_added().GetComponent <MovingObject>();
         // initalize boxcar position
         PositionPair pos_pair = TrainRouteManager.get_initial_destination(last_vehicle, tilemap);
         initialize_position(boxcar_component, pos_pair);
         boxcar_component.set_initial_rotation(boxcar_component.orientation);
         //set_initial_angle(boxcar, boxcar_component);
         boxcar_component.city          = train.city;
         boxcar_component.station_track = train.station_track;
         boxcar_component.arrive_at_city();
         boxcar_component.initialize_boxcar(boxcar_counter);
         boxcar_component.is_wait_for_turntable = true;
         train.boxcar_squad.Add(boxcar);
         // save gameobject tile with adjustments. when a user clicks on a tile, it will be in the tile opposite the vehicle's orientation. Therefore, flip orientation
         //Vector2Int boxcar_board_position = RouteManager.get_straight_next_tile_pos(TrackManager.flip_straight_orientation(boxcar_component.orientation), (Vector2Int)boxcar_component.tile_position);
         boxcar_component.city.city_board[pos_pair.tile_dest_pos.x + 1, pos_pair.tile_dest_pos.y + 1] = boxcar; // offset boxcar to be consistent
         //print("new boxcar created at tile position " + boxcar_component.tile_position);
     }
 }
Exemple #2
0
        public TeleportView(Scene scene, PositionPair pos)
        {
            dataMap = new DataMap();

            Obj            = Mesh.CreateTorus("torus", 10, 1, 10, scene);
            Obj.position.z = globalX = (decimal)(dataMap.sizeMapX * (-4.5) + (pos.pairPosition[0].x * 10.15));
            Obj.position.x = globalY = (decimal)(dataMap.sizeMapY * (-4.5) + (pos.pairPosition[0].y * 10.15));
            if (pos.pairPosition[0].z == 0)
            {
                Obj.position.y = 1;
            }
            else
            {
                Obj.position.y = (decimal)5 * (pos.pairPosition[0].z + pos.pairPosition[0].z);
            }


            Obj2            = Mesh.CreateTorus("torus", 10, 1, 8, scene);
            Obj2.position.z = globalX = (decimal)(dataMap.sizeMapX * (-4.5) + (pos.pairPosition[1].x * 10.15));
            Obj2.position.x = globalY = (decimal)(dataMap.sizeMapY * (-4.5) + (pos.pairPosition[1].y * 10.15));
            if (pos.pairPosition[1].z == 0)
            {
                Obj2.position.y = 1;
            }
            else
            {
                Obj2.position.y = (decimal)5 * (pos.pairPosition[1].z + pos.pairPosition[1].z);
            }

            materialBox = new StandardMaterial("temp", scene);
            materialBox.diffuseColor = new Color3(pos.red, pos.green, pos.blue);
            Obj.material             = materialBox;
            Obj2.material            = materialBox;
        }
        private IList <ComparisonDiff> GetAllDiffs(PositionPair pair)
        {
            var defaultDiffPosition = pair.LeftPart.Length;
            var currentDiffStart    = pair.LeftPart.Length;
            var diffs = new Dictionary <long, long>();

            for (var i = 0; i < pair.LeftPart.Length; i++)
            {
                if (pair.LeftPart[i] != pair.RightPart[i])
                {
                    if (currentDiffStart == defaultDiffPosition)
                    {
                        currentDiffStart = i;
                        diffs.Add(currentDiffStart, 1);
                    }
                    else
                    {
                        diffs[currentDiffStart] += 1;
                    }
                }
                else
                {
                    currentDiffStart = defaultDiffPosition;
                }
            }
            return(diffs.Select(d => new ComparisonDiff(d.Key, d.Value)).ToList());
        }
 public PositionPair(PositionPair p) : this(bwapiPINVOKE.new_PositionPair__SWIG_2(PositionPair.getCPtr(p)), true)
 {
     if (bwapiPINVOKE.SWIGPendingException.Pending)
     {
         throw bwapiPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public bool Equals(PositionPair obj)
 {
     if (obj == null)
     {
         return(false);
     }
     return(obj.swigCPtr.Handle == this.swigCPtr.Handle);
 }
 public static void initialize_position(MovingObject moving_object, PositionPair pos_pair)
 {
     moving_object.tile_position         = new Vector3Int(pos_pair.tile_dest_pos.x, pos_pair.tile_dest_pos.y, 0);
     moving_object.next_tilemap_position = pos_pair.tile_dest_pos;
     moving_object.prev_tile_position    = (Vector3Int)pos_pair.prev_tile_dest_pos;
     moving_object.transform.position    = pos_pair.abs_dest_pos;
     moving_object.orientation           = pos_pair.orientation;
     moving_object.final_orientation     = pos_pair.orientation;
 }
Exemple #7
0
        public void Get_WithNoSuchItem_ShouldReturnNull()
        {
            var pair = new PositionPair(1);

            _dataRepository.AddOrUpdate(pair);

            var testPair = _dataRepository.Get(2);

            Assert.Null(testPair);
        }
        public void Compare_Nulls_AreEqual()
        {
            var newPair = new PositionPair(10);

            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Left, null);
            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, null);

            var exception = Assert.Throws <Exception>(() => _comparisonService.Compare(newPair.Id));

            Assert.Equal("Comparison pair with id = 10 is incomplete", exception.Message);
        }
 /// <summary>
 /// Creates new position pair or updates if it is already exist
 /// </summary>
 /// <param name="pair">Position pair to be created or updated</param>
 public void AddOrUpdate(PositionPair pair)
 {
     if (_positionPairs.ContainsKey(pair.Id))
     {
         Update(pair);
     }
     else
     {
         Add(pair);
     }
 }
    public static PositionPair get_destination(TrafficLightManager moving_thing, Tilemap tilemap, Vector2 offset)
    {
        // modify by offset for a person boarding a train (so hes not standing on the tracks)
        Vector3Int   tile_coord       = new Vector3Int(moving_thing.tile_position[0], moving_thing.tile_position[1], 0);
        Tile         track_tile       = (Tile)tilemap.GetTile(tile_coord);
        Vector2      tile_world_coord = tilemap.GetCellCenterWorld(tile_coord);
        PositionPair pos_pair         = get_next_tile_pos(tilemap, track_tile, moving_thing, tile_coord, offset);
        Tile         city_tile        = (Tile)city_tilemap.GetTile(tile_coord);

        return(pos_pair);
    }
Exemple #11
0
        public void Delete_ShouldReturnNullAfterDelete()
        {
            var pair = new PositionPair(35);

            _dataRepository.AddOrUpdate(pair);
            _dataRepository.Delete(35);

            var testPair = _dataRepository.Get(35);

            Assert.Null(testPair);
        }
Exemple #12
0
        public void Add_NewAddedPair_ShouldBeInList(int id)
        {
            var pair = new PositionPair(id);

            _dataRepository.AddOrUpdate(pair);

            var testPair = _dataRepository.Get(id);

            Assert.NotNull(testPair);
            Assert.True(testPair.Id == id);
        }
        /// <summary>
        /// Creates new or updates pair's position part data.
        /// </summary>
        /// <param name="id">Position pair identifier</param>
        /// <param name="position">Position part</param>
        /// <param name="data">Binary array of data</param>
        public void AddOrUpdateData(int id, PositionType position, byte[] data)
        {
            var pair = _repository.Get(id);

            if (pair == null)
            {
                pair = new PositionPair(id);
            }

            SetPositionPartData(pair, position, data);
            _repository.AddOrUpdate(pair);
        }
        public void Compare_TheSameContent_IsEqual()
        {
            var newPair = new PositionPair(10);
            var hello   = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };

            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Left, hello);
            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, hello);

            var comparisonResult = _comparisonService.Compare(newPair.Id);

            Assert.Equal(new ComparisonResult(EqualityType.Equals), comparisonResult);
        }
Exemple #15
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            _isMouseDown = false;
            if (_Game == null)
            {
                return;
            }
            for (int x = 1; x <= 8; x++)
            {
                for (int y = 1; y <= 8; y++)
                {
                    if (!this.Rectangles[x - 1, y - 1].Contains(e.Location) || this.SelectedPiece == null)
                    {
                        continue;
                    }
                    //开始移动
                    Position tgtPosition = new Position(x, y);
                    //吃子
                    foreach (Position pos in EnableCapturePosition)
                    {
                        if (pos.Equals(tgtPosition))
                        {
                            PositionPair pair = new PositionPair(this.SelectedPosition, tgtPosition);
                            _Game.PieceMoveIn(pair);
                            OnPlay(new PlayEventArgs());
                            goto forEnd;
                        }
                    }
                    //仅移动
                    foreach (Position pos in EnableMoveInPosition)
                    {
                        if (pos.Equals(tgtPosition))
                        {
                            PositionPair pair = new PositionPair(this.SelectedPosition, tgtPosition);
                            _Game.PieceMoveIn(pair);
                            OnPlay(new PlayEventArgs());
                            goto forEnd;
                        }
                    }
                    break;
                }
            }
forEnd:
            this.SelectedPosition       = Position.Empty;
            this.EnableMoveInPosition   = null;
            this.SelectedPiece          = null;
            this.SelectedPieceImage     = null;
            this.SelectedMovedRectangle = Rectangle.Empty;
            this.Cursor = Cursors.Default;
            this.Refresh();
        }
        public void Compare_DifferentLength_NotEqual()
        {
            var newPair    = new PositionPair(10);
            var hello      = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            var helloWorld = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 72, 0x6c, 0x64 };

            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Left, hello);
            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, helloWorld);

            var comparisonResult = _comparisonService.Compare(newPair.Id);

            Assert.Equal(new ComparisonResult(EqualityType.SizeDoNotMatch), comparisonResult);
        }
        public void Compare_TheSameLength_NotEqual()
        {
            var newPair = new PositionPair(10);
            var hello   = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            var herro   = new byte[] { 0x48, 0x65, 0x72, 0x72, 0x6f };

            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Left, hello);
            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, herro);

            var comparisonResult = _comparisonService.Compare(newPair.Id);

            Assert.Equal(EqualityType.ContentDoNotMatch, comparisonResult.Equality);
        }
        public void Update_ShouldBeUpdatedInList()
        {
            var newPair = new PositionPair(100)
            {
                RightPart = new byte[] { 0xBE, 0xBE, 0xBE }
            };
            var newRightPart = new byte[] { 0xCE, 0xCE, 0xCE };

            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, newPair.RightPart);
            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, newRightPart);

            var testPair = _dataRepository.Get(newPair.Id);

            Assert.True(testPair.RightPart.SequenceEqual(newRightPart));
        }
        public void Add_NewAddedPair_ShouldBeInList()
        {
            const int id   = 1;
            var       pair = new PositionPair(id)
            {
                LeftPart = new byte[] { 0xBE, 0xBE, 0xBE }
            };

            _comparisonService.AddOrUpdateData(pair.Id, PositionType.Left, pair.LeftPart);

            var testPair = _dataRepository.Get(pair.Id);

            Assert.NotNull(testPair);
            Assert.True(testPair.LeftPart.SequenceEqual(pair.LeftPart));
        }
        private void SetPositionPartData(PositionPair pair, PositionType position, byte[] data)
        {
            switch (position)
            {
            case PositionType.Left:
                pair.LeftPart = data;
                break;

            case PositionType.Right:
                pair.RightPart = data;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(position), position, null);
            }
        }
        public void Compare_TheSameLength_CorrectDiff()
        {
            var newPair = new PositionPair(10);
            var hello   = new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f };
            var herro   = new byte[] { 0x48, 0x65, 0x72, 0x72, 0x6f };

            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Left, hello);
            _comparisonService.AddOrUpdateData(newPair.Id, PositionType.Right, herro);

            var comparisonResult = _comparisonService.Compare(newPair.Id);
            var diff             = comparisonResult.Diff.FirstOrDefault();

            Assert.NotNull(comparisonResult.Diff);
            Assert.NotNull(diff);
            Assert.True(diff.Offset == 2);
            Assert.True(diff.Length == 2);
        }
Exemple #22
0
        public Position UseTeleport(Position currPosition)
        {
            //Говнокод
            if (tempDataTeleport.Any(s => s.pairPosition[0].IsEquality(currPosition)))
            {
                PositionPair abc = new PositionPair();
                abc = tempDataTeleport.FirstOrDefault(s => s.pairPosition[0].IsEquality(currPosition));
                return(abc.pairPosition[1]);
            }

            if (tempDataTeleport.Any(s => s.pairPosition[1].IsEquality(currPosition))) //Если существует в 2 ячейке pair
            {
                PositionPair abc = new PositionPair();
                abc = tempDataTeleport.FirstOrDefault(s => s.pairPosition[1].IsEquality(currPosition));
                return(abc.pairPosition[0]);
            }

            return(currPosition);
        }
Exemple #23
0
        public void Update_ShouldBeUpdatedInList()
        {
            var newPair = new PositionPair(100)
            {
                LeftPart  = new byte[] { 0xBE, 0xBE, 0xBE },
                RightPart = new byte[] { 0xCE, 0xCE, 0xCE }
            };
            var pairToUpdate = new PositionPair(100)
            {
                LeftPart  = new byte[] { 0xCE, 0xCE, 0xCE },
                RightPart = new byte[] { 0xBE, 0xBE, 0xBE }
            };

            _dataRepository.AddOrUpdate(pairToUpdate);

            var testPair      = _dataRepository.Get(pairToUpdate.Id);
            var partsAreEqual = testPair.LeftPart.SequenceEqual(pairToUpdate.LeftPart) &&
                                testPair.RightPart.SequenceEqual(pairToUpdate.RightPart);

            Assert.True(partsAreEqual);
        }
    public static PositionPair get_initial_destination(MovingObject vehicle, Tilemap tilemap)
    {
        Orientation original_orientation       = vehicle.orientation;
        Orientation original_final_orientation = vehicle.final_orientation;
        Tile        track_tile = (Tile)tilemap.GetTile(vehicle.tile_position);

        vehicle.orientation = TrackManager.flip_straight_orientation(vehicle.orientation);
        PositionPair prev_pos_pair   = get_next_tile_pos(tilemap, track_tile, vehicle, vehicle.tile_position, new Vector2(0, 0)); // opposite direction of train to get prev tile
        Vector3Int   prev_tile_coord = (Vector3Int)prev_pos_pair.tile_dest_pos;

        track_tile = (Tile)tilemap.GetTile(prev_tile_coord);
        string       track_name = track_tile.name;
        PositionPair pos_pair   = get_next_tile_pos(tilemap, track_tile, vehicle, prev_tile_coord, new Vector2(0, 0)); // USE ABS DEST POS of prev prev tile TO SET TRANSFORM POSITION

        TrackManager.set_opposite_direction(track_name, vehicle);                                                      // set direction same as train
        pos_pair.tile_dest_pos    = prev_pos_pair.tile_dest_pos;                                                       // use previous tile, not the previous previous tile
        pos_pair.orientation      = vehicle.orientation;
        vehicle.orientation       = original_orientation;                                                              // restore original orientation
        vehicle.final_orientation = original_final_orientation;
        return(pos_pair);
    }
    public static PositionPair get_destination(Simple_Moving_Object moving_thing, Tilemap tilemap, Vector2 offset)
    {
        // modify by offset for a person boarding a train (so hes not standing on the tracks)
        Vector3Int   tile_coord       = new Vector3Int(moving_thing.tile_position[0], moving_thing.tile_position[1], 0);
        Tile         track_tile       = (Tile)tilemap.GetTile(tile_coord);
        Vector2      tile_world_coord = tilemap.GetCellCenterWorld(tile_coord);
        PositionPair pos_pair         = get_next_tile_pos(tilemap, track_tile, moving_thing, tile_coord, offset);

        if (moving_thing.gameObject.tag == "boxcar")
        {
            Boxcar bcar = (Boxcar)moving_thing;
        }
        if (!moving_thing.in_city) //not inside a city, so check if arrived at city
        {
            Tile city_tile = (Tile)city_tilemap.GetTile(tile_coord);
            if (city_tile != null)                                                                                   //check if arriving at city
            {
                City city = CityManager.instance.gameobject_board[tile_coord.x, tile_coord.y].GetComponent <City>(); // check if city arrived at is not the same city we're leaving
                pos_pair.abs_dest_pos = tile_world_coord;                                                            // destination is the center of the tile
                moving_thing.prepare_to_arrive_at_city(city);
            }
        }
        return(pos_pair);
    }
Exemple #26
0
 public virtual PositionPair getSides() {
   PositionPair ret = new PositionPair(bwtaPINVOKE.Chokepoint_getSides(swigCPtr), false);
   return ret;
 }
Exemple #27
0
        public virtual PositionPair getSides()
        {
            PositionPair ret = new PositionPair(bwtaPINVOKE.Chokepoint_getSides(swigCPtr), false);

            return(ret);
        }
Exemple #28
0
        /// <summary>
        /// 移动指定位置棋格的棋子
        /// </summary>
        /// <param name="pair">指定的成对的位置,First值为源棋格,Second值是目标棋格</param>
        public void PieceMoveIn(PositionPair pair)
        {
            Enums.ActionCollection actions = new Enums.ActionCollection();
            Piece piece;
            if (this.TryGetPiece(pair.First.Dot, out piece))
            {
                //第1步,判断一下过路兵的格子的逻辑
                if (piece is PiecePawn)
                {
                    if (pair.First.Y == pair.Second.Y)
                    {
                        return;
                    }
                }
                actions.Add(Enums.Action.General);
                //第2步,判断目标棋格中是否有棋子。
                //如果有棋子,更改Action,调用PieceMoveOut方法。
                if (this.ContainsPiece(pair.Second.Dot))
                {
                    actions.Add(Enums.Action.Capture);
                    this.PieceMoveOut(pair.Second);
                }

                //第3步,调用内部方法PieceMoveIn,移动棋子,并更改FEN记录
                this.PieceMoveIn(piece, actions, pair.First, pair.Second);

                //第4步,如上一步棋出现过“过路兵”的局面,而现在进行了新的一步棋了,故而取消上一步棋的“过路兵”局面。
                if (_piecePawnByEnPassanted != null)
                {
                    _piecePawnByEnPassanted.EnableEnPassanted = false;
                    _piecePawnByEnPassanted = null;
                }

                //第5步,判断是否过路兵的局面
                if (piece is PiecePawn)
                {
                    #region 过路兵
                    //成为能被吃过路兵的“兵”
                    if ((pair.First.Y == 1 && pair.Second.Y == 3) || (pair.First.Y == 6 && pair.Second.Y == 4))
                    {
                        char pawnChar;
                        Position tmpPos = pair.Second.ShiftWest();
                        if (tmpPos != null)
                        {
                            if (this.TryGetPiece(tmpPos.Dot, out pawnChar))
                            {
                                Enums.GameSide side = char.IsLower(pawnChar) ? Enums.GameSide.Black : Enums.GameSide.White;
                                if (this.GameSide == side)
                                {
                                    _piecePawnByEnPassanted = piece as PiecePawn;
                                    _piecePawnByEnPassanted.EnableEnPassanted = true;
                                }
                            }
                        }
                        tmpPos = pair.Second.ShiftEast();
                        if (tmpPos != null)
                        {
                            if (this.TryGetPiece(tmpPos.Dot, out pawnChar))
                            {
                                Enums.GameSide side = char.IsLower(pawnChar) ? Enums.GameSide.Black : Enums.GameSide.White;
                                if (this.GameSide == side)
                                {
                                    _piecePawnByEnPassanted = piece as PiecePawn;
                                    _piecePawnByEnPassanted.EnableEnPassanted = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        ((PiecePawn)piece).EnableEnPassanted = false;
                    }
                    #endregion
                }

                //第6步,移动棋子后,根据移动棋子后的局面生成Action,主要是判断另一战方的“王”是否被将军
                actions.Add(this.IsCheckPieceKing(piece));

                //第7步,注册棋子移动后事件
                OnPieceMoveInEvent(piece, actions, pair);
            }
        }
Exemple #29
0
 protected virtual void OnPieceMoveInEvent(Piece piece, Enums.ActionCollection actions, PositionPair pair)
 {
     if (PieceMoveInEvent != null)
     {
         PieceMoveInEvent(piece, actions, pair);
     }
 }
 public PositionPair(PositionPair p) : this(bwapiPINVOKE.new_PositionPair__SWIG_2(PositionPair.getCPtr(p)), true) {
   if (bwapiPINVOKE.SWIGPendingException.Pending) throw bwapiPINVOKE.SWIGPendingException.Retrieve();
 }
public bool Equals(PositionPair obj) 
{
    if (obj == null) return false;
    return (obj.swigCPtr.Handle == this.swigCPtr.Handle);
}
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PositionPair obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
 private void Add(PositionPair pair)
 {
     _positionPairs.Add(pair.Id, pair);
 }
 private void Update(PositionPair pair)
 {
     _positionPairs[pair.Id] = pair;
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PositionPair obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
Exemple #36
0
        }                                          // Teleport [ pos1 <===> pos2 ]

        public Teleport(PositionPair pos)
        {
            position = pos;
        }